|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
The following example creates a workflow step.
private bool CreateWorkflowStep() { // Get the workflow WorkflowInfo myWorkflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow"); if (myWorkflow != null) { // Create new workflow step object WorkflowStepInfo newStep = new WorkflowStepInfo();
// Set the properties newStep.StepWorkflowID = myWorkflow.WorkflowID; newStep.StepName = "MyNewWorkflowStep"; newStep.StepDisplayName = "My new workflow step"; newStep.StepOrder = 1;
// Save the step into database WorkflowStepInfoProvider.SetWorkflowStepInfo(newStep);
// Ensure correct step order WorkflowStepInfoProvider.InitStepOrders(newStep.StepWorkflowID);
return true; }
return false; } |
The following example adds a role to the workflow step created by the code example above. Members of the added role will be able to approve documents in the step.
private bool AddRoleToStep() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");
if (workflow != null) { // Get the custom step WorkflowStepInfo step = WorkflowStepInfoProvider.GetWorkflowStepInfo("MyNewWorkflowStep", workflow.WorkflowID);
if (step != null) { // Get the role to be assigned to the step RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSEditor", CMSContext.CurrentSiteID);
if (role != null) { // Make the assignment WorkflowStepRoleInfoProvider.AddRoleToWorkflowStep(step.StepID, role.RoleID);
return true; } else { // Role was not found apiAddRoleToStep.ErrorMessage = "Role 'CMS Editors' was not found."; } } else { // Step was not found apiAddRoleToStep.ErrorMessage = "Step 'My new workflow step' was not found."; } }
return false; } |
The following example removes the role added by the above code example from the workflow step.
bool RemoveRoleFromStep() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");
if (workflow != null) { // Get the custom step WorkflowStepInfo step = WorkflowStepInfoProvider.GetWorkflowStepInfo("MyNewWorkflowStep", workflow.WorkflowID);
if (step != null) { // Get the role to be assigned to the step RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSEditor", CMSContext.CurrentSiteID);
if (role != null) { // Get the step - role relationship WorkflowStepRoleInfo stepRoleInfo = WorkflowStepRoleInfoProvider.GetWorkflowStepRoleInfo(step.StepID, role.RoleID);
if (stepRoleInfo != null) { // Remove the assignment WorkflowStepRoleInfoProvider.RemoveRoleFromWorkflowStep(step.StepID, role.RoleID);
return true; } else { // The role is not assigned to the step apiRemoveRoleFromStep.ErrorMessage = "The 'CMS Editors' role is not assigned to the step."; } } else { // The role was not found apiRemoveRoleFromStep.ErrorMessage = "The role 'CMS Editors' was not found."; } } else { // The step was not found apiRemoveRoleFromStep.ErrorMessage = "The step 'My new workflow step' was not found."; } }
return false; } |
The following example deletes the workflow step created by the first example on this page.
private bool DeleteWorkflowStep() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");
if (workflow != null) { // Get the custom step WorkflowStepInfo deleteStep = WorkflowStepInfoProvider.GetWorkflowStepInfo("MyNewWorkflowStep", workflow.WorkflowID);
if (deleteStep != null) { // Remove the step WorkflowStepInfoProvider.DeleteWorkflowStepInfo(deleteStep); return true; } }
return false; } |