Set workflow based on user

Nat Tam asked on May 14, 2015 12:23

Does anyone know if it is possible to assign a specific workflow to a new page when it is created based on properties of the CMS editor?

For example, we're building a site with a News area. CMS editors from different divisions in the company will be able to contribute news articles, but articles for different divisions will be subject to different workflows.

I'm hoping I can do this by handling the Document Insert global event. Does anyone know if this is possible? And if so, some example code would be amazing. Thanks.

Correct Answer

Rui Wang answered on May 14, 2015 16:13

You may also consider use the Advance Workflow (https://docs.kentico.com/display/K82/Designing+advanced+workflows)

Which you can set different workflow path, then use the condition check to check editors' ROLE and decide which path to go through.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on May 14, 2015 13:30

A simple way would be to set your page structure up to reflect this and simply set edit abilities at the division level:

/News
/News/Division <-- edit security here by division group
/News/Division/News item

Otherwise setup your different workflows by division and as you stated handle the Insert event for that page type and send it to the proper workflow based on a fields value (division).

1 votesVote for this answer Mark as a Correct answer

Nat Tam answered on May 14, 2015 15:17 (last edited on May 14, 2015 15:22)

Thanks Brenden. The first example isn't feasible because the client doesn't wish their internal structure to be represented on the website.

I'm glad it's possible to apply a workflow programmatically though. Do you happen to know how to do this? I'm looking at the WorkflowManager property of TreeNode which provides a lot of workflow-related methods and properties, but I can't find anything that might let me set the workflow. I'd really appreciate some guidance.

(I note that VersionManager has a RemoveWorkflow method, but no AddWorkflow or similar...)

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on May 14, 2015 15:30

Set it in the Global Event Handler. Fire off the method in the Document_Insert_After or Document_Update_After. I don't have exact code available but you will also be doing it in the tree context for the current user. I would have to postulate the steps are:

//Get Tree for current user.
            TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
//Get Workflow for node.
                WorkflowInfo workflow = workflowManager.GetNodeWorkflow(node);

if (workflow == null)
{
 // Assign workflow based on logic for the current user.  So get your user, get their properties run you logic statement then assign the workflow to the tree object.
}
0 votesVote for this answer Mark as a Correct answer

Nat Tam answered on May 14, 2015 15:34

Thanks Charles, but what I'm looking for is the method that lets me add a workflow to a document in code. As I say, it looks like I can use VersionManager to remove a workflow but not add one...

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on May 14, 2015 15:42 (last edited on May 14, 2015 15:44)

Did you check the API examples in Kentico ? Under Content Management > Workflow Advanced view the Create example objects. About two thirds of the way down through the code there, you will see how to assign a workflow or at least take inspiration from it to accomplish what you need.

Workflows, I believe are assigned by Scope.

1 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on May 14, 2015 16:14 (last edited on May 14, 2015 16:16)

Advanced workflow is available only to EMS edition. I would assume since the question was asked that they are on ultimate or below.

0 votesVote for this answer Mark as a Correct answer

Nat Tam answered on May 14, 2015 16:53 (last edited on May 14, 2015 16:53)

Thanks again Charles. But no, the API examples don't include an example for assigning workflow programmatically. They all assume the document already has a workflow. If anyone happens to know the answer I'd be interested. However...

...thanks Rui, I had actually come to the same conclusion. I think you're right that Advanced Workflow is the way to go for this purpose.

(@Charles - no, I simply hadn't considered that option - relatively new to Kentico!)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.