API
Version 7.x > API > Workflow - moving to a Condition step View modes: 
User avatar
Certified Developer v6
Certified Developer v6
Dave - 8/30/2013 3:04:05 PM
   
Workflow - moving to a Condition step
Hi,

I'm using the WorkflowManager to move TreeNode through a few steps setup in my Advanced Workflow. One of the steps is a Condition step that hooks into a custom macro. If I push it through these steps manually (through the CMS Desk interface), the macro is triggered and the TreeNode moves through the step. If I use workflowManager.MoveToNextStep(), it "stops" at the Condition step. What do I need to do to trigger this step's condition and have it continue through the workflow if it passes the macro condition?

Thanks!
Dave

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/31/2013 1:10:31 AM
   
RE:Workflow - moving to a Condition step
Hello,

What is the macro like and I assume you are doing it in the code right?
If so, how is the macro resolved in this case? Are you resolving the macro in your code too?

Best regards,
Juraj Ondrus

User avatar
Certified Developer v6
Certified Developer v6
Dave - 9/18/2013 10:10:07 AM
   
RE:Workflow - moving to a Condition step
Hey Juraj,

I'm using a Macro Rule in the Workflow section. The macro is registered with the CMSModuleLoader partial class. I'm only referencing the macro in the Condition Step itself, not in my API code that moves the TreeNode through the workflow.

Thanks,
Dave

User avatar
Certified Developer v6
Certified Developer v6
Dave - 9/20/2013 12:45:59 PM
   
RE:Workflow - moving to a Condition step
This is the code I am using:


DocumentHelper.InsertDocument(node, parentNode.NodeID, provider);

node.CheckIn(null, null);
WorkflowManager workflowManager = WorkflowManager.GetInstance(provider);

using (CMS.SettingsProvider.CMSActionContext cmsActionContext = new CMS.SettingsProvider.CMSActionContext())
{
cmsActionContext.AllowAsyncActions = false;

workflowManager.PublishDocument(node, null);

var step = workflowManager.MoveToNextStep(node, null);
}

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 9/23/2013 2:01:32 AM
   
RE:Workflow - moving to a Condition step
Hi,

Thank you. This code looks OK. What is the custom macro code, please?
The only possible cause, at this moment, we see is that the macro code runs e.g. current user context, which could be public user and then the macro is not executed.

Best regards,
Juraj Ondrus

User avatar
Certified Developer v6
Certified Developer v6
Dave - 9/23/2013 8:30:30 AM
   
RE:Workflow - moving to a Condition step
Hey Juraj,

This is the Macro Rule condition code:


return {_has}Document.LCARSHasProjectMetaData()


And this is the macro's code itself:


MacroMethod updateProjectMetaData = new MacroMethod("LCARSHasProjectMetaData", LCARSHasProjectMetaData)
{
Comment = "Returns true if project has metadata. Attempts to retrieve if it does not.",
Type = typeof(bool),
AllowedTypes = new List<Type>() { typeof(TreeNode) },
MinimumParameters = 1
};
updateProjectMetaData.AddParameter("document", typeof(TreeNode), "Project document");
MacroMethods.RegisterMethod(updateProjectMetaData);


public static object LCARSHasProjectMetaData(params object[] parameters)
{
switch (parameters.Length)
{
case 1:
return LCARSHasProjectMetaData(parameters[0] as TreeNode);
}

return null;
}

public static bool LCARSHasProjectMetaData(TreeNode node)
{
var id = ValidationHelper.GetString(node["ProjectID"], String.Empty);

if (!String.IsNullOrWhiteSpace(id))
{
var manager = Dependencies.CreateManager();

var has = manager.HasProjectMetaData(id);

return has;
}

return false;
}


Behind manager.HasProjectMetaData, this is the only code that would use a user context that I know of:


var provider = new TreeProvider();

var parameters = new NodeSelectionParameters();
parameters.Where = string.Format("ProjectID = '{0}'", id);
parameters.SiteName = this.settingsProvider.SiteName;
parameters.ClassNames = this.settingsProvider.ProjectClassName;
parameters.AliasPath = null;
parameters.SelectOnlyPublished = false;

var node = provider.SelectSingleNode(parameters);

if (node != null)
{
return TreeNode.New<Project>(node, this.settingsProvider.ProjectClassName, provider);
}

return null;


User avatar
Certified Developer v6
Certified Developer v6
Dave - 10/1/2013 9:00:18 AM
   
RE:Workflow - moving to a Condition step
RESOLUTION:

I found out that this was actually a case of the User not having the proper permissions for the Workflow Step Branches/Cases I was trying to pass it through. Once I setup the permissions in the Security section of the Workflow Step, everything worked.

Thanks!
Dave