|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
The following example moves the document under workflow created in the Sample documents and objects topic to the subsequent workflow step.
private bool MoveToNextStep() { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Prepare parameters string siteName = CMSContext.CurrentSiteName; string aliasPath = "/API-Example"; string culture = "en-us"; bool combineWithDefaultCulture = false; string classNames = TreeProvider.ALL_CLASSNAMES; string where = null; string orderBy = null; int maxRelativeLevel = -1; bool selectOnlyPublished = false; string columns = null;
// Get the document TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);
if (node != null) { WorkflowManager workflowManager = new WorkflowManager(tree);
WorkflowInfo workflow = workflowManager.GetNodeWorkflow(node);
// Check if the document uses workflow if (workflow != null) { // Check if the workflow doesn't use automatic publishing, otherwise, documents can't change workflow steps. if (!workflow.WorkflowAutoPublishChanges) { // Check if the current user can move the document to the next step if (workflowManager.CanUserApprove(node)) { // Move the document to the next step workflowManager.MoveToNextStep(node, null);
return true; } else { apiMoveToNextStep.ErrorMessage = "You are not authorized to approve the document."; } } else { apiMoveToNextStep.ErrorMessage = "The document uses versioning without workflow, changes are published automatically."; } } else { apiMoveToNextStep.ErrorMessage = "The document doesn't use workflow."; } }
return false; } |
The following example moves the document under workflow created in the Sample documents and objects topic to the previous workflow step.
private bool MoveToPreviousStep() { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Prepare parameters string siteName = CMSContext.CurrentSiteName; string aliasPath = "/API-Example"; string culture = "en-us"; bool combineWithDefaultCulture = false; string classNames = TreeProvider.ALL_CLASSNAMES; string where = null; string orderBy = null; int maxRelativeLevel = -1; bool selectOnlyPublished = false; string columns = null;
// Get the document TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);
if (node != null) { WorkflowManager workflowManager = new WorkflowManager(tree);
WorkflowInfo workflow = workflowManager.GetNodeWorkflow(node);
// Check if the document uses workflow if (workflow != null) { // Check if the workflow doesn't use automatic publishing, otherwise, documents can't change workflow steps. if (!workflow.WorkflowAutoPublishChanges) { // Check if the current user can move the document to the next step if (workflowManager.CanUserApprove(node)) { // Move the document to the previous step workflowManager.MoveToPreviousStep(node, null);
return true; } else { apiMoveToPreviousStep.ErrorMessage = "You are not authorized to reject the document."; } } else { apiMoveToPreviousStep.ErrorMessage = "The document uses versioning without workflow, changes are published automatically."; } } else { apiMoveToPreviousStep.ErrorMessage = "The document doesn't use workflow."; } }
return false; } |
The following example archives the document under workflow created in the Sample documents and objects topic.
private bool ArchiveDocument() { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Prepare parameters string siteName = CMSContext.CurrentSiteName; string aliasPath = "/API-Example"; string culture = "en-us"; bool combineWithDefaultCulture = false; string classNames = TreeProvider.ALL_CLASSNAMES; string where = null; string orderBy = null; int maxRelativeLevel = -1; bool selectOnlyPublished = false; string columns = null;
// Get the document TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);
if (node != null) { WorkflowManager workflowManager = new WorkflowManager(tree);
WorkflowInfo workflow = workflowManager.GetNodeWorkflow(node);
// Check if the document uses workflow if (workflow != null) { // Archive the document workflowManager.ArchiveDocument(node, null);
return true; } else { apiArchiveDocument.ErrorMessage = "The document doesn't use workflow."; } }
return false; } |