API
Version 7.x > API > Pass value from one Workflow action to the next View modes: 
User avatar
Member
Member
brian.olson-hfit - 4/26/2013 6:07:16 AM
   
Pass value from one Workflow action to the next
We are trying to develop a couple of custom workflow actions that either maintain state between steps, or pass a value from one action to the next.

So for example, we might have one action that looks up a document and then passes that document Id to the next action in the workflow.

So far we are not having much luck figuring out how to do this. Any thoughts?


User avatar
Member
Member
kentico_sandroj - 4/27/2013 5:57:51 PM
   
RE:Pass value from one Workflow action to the next
Hi Brian,

Have you had a chance to take a look at the developers guide article on developing custom action steps? It may give you the information you are looking for - if not, please let me know.

One option for passing the values could be writing/reading from a custom table:

private bool GetAndUpdateCustomTableItem()
{
// Create new Custom table item provider
CustomTableItemProvider customTableProvider = new CustomTableItemProvider(CMSContext.CurrentUser);

string customTableClassName = "customtable.sampletable";

// Check if Custom table 'Sample table' exists
DataClassInfo customTable = DataClassInfoProvider.GetDataClass(customTableClassName);
if (customTable != null)
{
// Prepare the parameters
string where = "ItemText LIKE N'New text'";
int topN = 1;
string columns = "ItemID";

// Get the data set according to the parameters
DataSet dataSet = customTableProvider.GetItems(customTableClassName, where, null, topN, columns);

if (!DataHelper.DataSourceIsEmpty(dataSet))
{
// Get the custom table item ID
int itemID = ValidationHelper.GetInteger(dataSet.Tables[0].Rows[0][0], 0);

// Get the custom table item
CustomTableItem updateCustomTableItem = customTableProvider.GetItem(itemID, customTableClassName);

if (updateCustomTableItem != null)
{
string itemText = ValidationHelper.GetString(updateCustomTableItem.GetValue("ItemText"), "");

// Set new values
updateCustomTableItem.SetValue("ItemText", itemText.ToLowerCSafe());

// Save the changes
updateCustomTableItem.Update();

return true;
}
}
}

return false;
}


Thanks,
Sandro

User avatar
Member
Member
brian.olson-hfit - 4/28/2013 8:26:55 AM
   
RE:Pass value from one Workflow action to the next

I think I found something that will work.

StateObject.StateCustomData.SetValue("Value", "Good");

This creates a stores the object (in this case the string "Good") under the key "Value". It appears that the object gets serialized and passed from step to step.

I can't find any reference to this in any documentation, but it appears to do what I need.


User avatar
Member
Member
kentico_sandroj - 4/28/2013 12:07:24 PM
   
RE:Pass value from one Workflow action to the next
Hi,

Thank you for sharing your solution. I tried to find more information about the method but I only found it in the API Reference (which I assume you're currently using) and a small example in ~\App_Code\CMSModules\OnlineMarketing\OnlineMarketingFunctions.cs line 750.

I will post links if I find anything else. In the meantime, let me know if you have any questions.

Thanks,
Sandro