Kentico CMS 6.0 Developer's Guide

Managing workflow scopes

Managing workflow scopes

Previous topic Next topic Mail us feedback on this topic!  

Managing workflow scopes

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


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 scope.

 

private bool CreateWorkflowScope()

{

  // Get the workflow

  WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");

 

  if (workflow != null)

   {

      // Create new workflow scope object

      WorkflowScopeInfo newScope = new WorkflowScopeInfo();

 

      // Get the site default culture from settings

      string cultureCode = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSDefaultCultureCode");

      CultureInfo culture = CultureInfoProvider.GetCultureInfo(cultureCode);

 

      // Get root document type class ID

      int classID = DataClassInfoProvider.GetDataClass("CMS.Root").ClassID;

 

      // Set the properties

       newScope.ScopeStartingPath = "/";

       newScope.ScopeCultureID = culture.CultureID;

       newScope.ScopeClassID = classID;

 

       newScope.ScopeWorkflowID = workflow.WorkflowID;

       newScope.ScopeSiteID = CMSContext.CurrentSiteID;

 

      // Save the workflow scope

      WorkflowScopeInfoProvider.SetWorkflowScopeInfo(newScope);

 

      return true;

   }

 

  return false;

}

 

The following example gets and updates the workflow scope created by the code example above.

 

private bool GetAndUpdateWorkflowScope()

{

 

  // Get the workflow

  WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");

 

  if (workflow != null)

   {

      // Get the workflow's scopes

      DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(workflow.WorkflowID);

 

      if (!DataHelper.DataSourceIsEmpty(scopes))

       {

          // Create the scope info object

          WorkflowScopeInfo updateScope = new WorkflowScopeInfo(scopes.Tables[0].Rows[0]);

 

          // Update the properties - the scope will include all cultures and document types

           updateScope.ScopeCultureID = 0;

           updateScope.ScopeClassID = 0;

 

          // Save the changes

          WorkflowScopeInfoProvider.SetWorkflowScopeInfo(updateScope);

 

          return true;

       }

      else

       {

          // No scope was found

           apiGetAndUpdateWorkflowScope.ErrorMessage = "The scope was not found.";

       }

   }

 

  return false;

}

 

The following example deletes the workflow scope created by the first example on this page.

 

private bool DeleteWorkflowScope()

{

  // Get the workflow

  WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");

 

  if (workflow != null)

   {

 

      // Get the workflow's scopes

      DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(workflow.WorkflowID);

 

      if (!DataHelper.DataSourceIsEmpty(scopes))

       {

          // Create the scope info object

          WorkflowScopeInfo deleteScope = new WorkflowScopeInfo(scopes.Tables[0].Rows[0]);

 

          // Delete the workflow scope

          WorkflowScopeInfoProvider.DeleteWorkflowScopeInfo(deleteScope);

 

          return true;

       }

      else

       {

          // No scope was found

           apiDeleteWorkflowScope.ErrorMessage = "The scope was not found.";

       }

   }

 

  return false;

}