CRMProcess.CreateAll Method
The CreateAll method creates a workflow process and all of its sub-elements.
Syntax
[Visual Basic .NET]
Public Function CreateAll(
ByVal Caller As CUserAuth,
ByVal Process As CWorkflowProcess
) As String
[C#]
public string CreateAll(
CUserAuth Caller,
CWorkflowProcess Process
);
[C++]
public: String* CreateAll(
CUserAuth* Caller,
CWorkflowProcess* Process
);
Parameters
Caller
Specifies the identity of the caller. To perform this action, the caller must have the prvCreateWorkflowProcess privilege. See CUserAuth.
Process
Specifies a CWorkflowProcess structure that stores a flat workflow process. See CWorkflowProcess.
Return Value
Returns a String type that specifies the ID of the new process.
Remarks
If there is an error, SOAP throws an exception and the error message is reported in System.Web.Services.Protocols.SoapException.Detail.OuterXml.
All IDs passed to the platform are GUIDs wrapped in braces. For example: {6522D89A-A752-4455-A2B0-51494C6957C3}
Example
[C#]
// strServer should be set with the name of the platform Web server
string strServer = "myservername";
// strVirtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string strVirtualDirectory = "mscrmservices";
string strDir = String.Concat("https://", strServer, "/",
strVirtualDirectory, "/");
// BizUser proxy object
Microsoft.Crm.Platform.Proxy.BizUser bizUser
= new Microsoft.Crm.Platform.Proxy.BizUser();
bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
bizUser.Url = String.Concat(strDir, "BizUser.srf");
// CRMProcess proxy object
Microsoft.Crm.Platform.Proxy.CRMProcess process
= new Microsoft.Crm.Platform.Proxy.CRMProcess();
process.Credentials = System.Net.CredentialCache.DefaultCredentials;
process.Url = String.Concat(strDir, "CRMProcess.srf");
string gregorId = "3B68EEAE-9977-4AA4-BC13-98FD4C2DFC17";
string deepakId = "09AAD3AF-21B3-4C67-B2B7-90C9CF87396A";
string contactStateId = "21090631-DB4F-4216-980A-F6CBF2701AC0";
string contactFirstNameId = "946B0CF4-FA98-41F1-9DD8-0AEB2C639310";
string contactLastNameId = "3A36CD9D-B5AB-4036-AFEA-9ECF65835D69";
string strErrorMsg;
string strProcessId;
Microsoft.Crm.Platform.Proxy.CWorkflowProcess oProcess;
try
{
Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = bizUser.WhoAmI();
// Instantiate the new process
oProcess = new Microsoft.Crm.Platform.Proxy.CWorkflowProcess();
// Make a new process that executes upon creation of a new contact
// rule 1: if state == "WA"
// step/action: Create a task for Gregor, telling him to review the new contact
// rule 2: else
// step/action: Create a task for Deepak, telling him to review the new contact
// Create the XML string for the process
Guid processId = Guid.NewGuid();
Guid initialStepId = Guid.NewGuid();
StringBuilder processXml = new StringBuilder("<wfprocess>");
processXml.Append("<name>Task Workflow Process</name>");
processXml.AppendFormat("<processid>{0}</processid>",
processId.ToString());
processXml.AppendFormat("<eventtypecode>{0}</eventtypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_EVENT_TYPE.WFET_CREATED.ToString());
processXml.AppendFormat("<initialstepid>{0}</initialstepid>",
initialStepId.ToString());
processXml.Append("<businessunitid>{5AB0481A-398B-49AB-BC98-74A277154A37}</businessunitid>");
processXml.Append("<usercontext>{3B68EEAE-9977-4AA4-BC13-98FD4C2DFC17}</usercontext>");
processXml.AppendFormat("<processtypecode>{0}</processtypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PROCESS_TYPE.WFPT_WORKFLOW_PROCESS);
processXml.Append("<processtypeversion>1</processtypeversion>");
processXml.AppendFormat("<entitytype>{0}</entitytype>",
Microsoft.Crm.Platform.Types.ObjectType.otContact.ToString());
processXml.Append("<description>Create a task when a new user is added</description>");
processXml.Append("<priority>100</priority>");
processXml.Append("</wfprocess>");
oProcess.Process = processXml.ToString();
// Create the XML string for the initial step
StringBuilder initialStepXml = new StringBuilder("<wfstep>");
initialStepXml.AppendFormat("<stepid>{0}</stepid>",
initialStepId.ToString());
initialStepXml.AppendFormat("<processid>{0}</processid>",
processId.ToString());
initialStepXml.Append("<name>Initial Step</name>");
initialStepXml.Append("<description>Entry step to hold the rules</description>");
initialStepXml.Append("</wfstep>");
// Create XML strings for rule, condition, and condition parameter to create a task for Gregor
Guid gregorRuleId = Guid.NewGuid();
Guid gregorStepId = Guid.NewGuid();
StringBuilder gregorRuleXml = new StringBuilder("<wfrule>");
gregorRuleXml.AppendFormat("<ruleid>{0}</ruleid>",
gregorRuleId.ToString());
gregorRuleXml.AppendFormat("<stepid>{0}</stepid>",
initialStepId.ToString());
gregorRuleXml.AppendFormat("<nextstepid>{0}</nextstepid>",
gregorStepId.ToString());
gregorRuleXml.Append("<orderofevaluation>1</orderofevaluation>");
gregorRuleXml.Append("<name>Gregor Task Rule</name>");
gregorRuleXml.Append("<description>Rule to determine whether Gregor should be given a task</description>");
gregorRuleXml.Append("</wfrule>");
Guid gregorConditionId = Guid.NewGuid();
StringBuilder gregorConditionXml = new StringBuilder("<wfcondition>");
gregorConditionXml.AppendFormat("<conditionid>{0}</conditionid>",
gregorConditionId.ToString());
gregorConditionXml.AppendFormat("<ruleid>{0}</ruleid>",
gregorRuleId.ToString());
gregorConditionXml.Append("<conditioncode>0</conditioncode>");
gregorConditionXml.Append("<name>E-mail Gregor Condition</name>");
gregorConditionXml.Append("<description>Give Gregor a task if the contact's state is WA</description>");
gregorConditionXml.Append("<orderofevaluation>1</orderofevaluation>");
gregorConditionXml.AppendFormat("<errorhandler>{0}</errorhandler>",
Microsoft.Crm.Platform.Types.WORKFLOW_ERROR_HANDLER_LEVEL.WFEH_WARNING);
gregorConditionXml.Append("</wfcondition>");
Guid equalsParameterId = Guid.NewGuid();
StringBuilder equalsParameter = new StringBuilder("<wfparameter>");
equalsParameter.AppendFormat("<parameterid>{0}</parameterid>",
equalsParameterId.ToString());
equalsParameter.AppendFormat("<conditionid>{0}</conditionid>",
gregorConditionId.ToString());
equalsParameter.AppendFormat("<parametertypecode>{0}</parametertypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PARAMETER_TYPE.WFPM_EQ);
equalsParameter.AppendFormat("<datatype>{0}</datatype>",
Microsoft.Crm.Platform.Types.WORKFLOW_DATA_TYPE.WFDT_BOOLEAN);
equalsParameter.Append("<orderofevaluation>1</orderofevaluation>");
equalsParameter.Append("<name>Equals Parameter</name>");
equalsParameter.Append("<description>Parameter to test the Contact's state</description>");
equalsParameter.Append("</wfparameter>");
StringBuilder contactStateParameter = new StringBuilder("<wfparameter>");
contactStateParameter.AppendFormat("<parameterid>{0}</parameterid>",
Guid.NewGuid().ToString());
contactStateParameter.AppendFormat("<conditionid>{0}</conditionid>",
gregorConditionId.ToString());
contactStateParameter.AppendFormat("<parentid>{0}</parentid>",
equalsParameterId.ToString());
contactStateParameter.AppendFormat("<parametertypecode>{0}</parametertypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PARAMETER_TYPE.WFPM_PROPERTY);
contactStateParameter.AppendFormat("<datatype>{0}</datatype>",
Microsoft.Crm.Platform.Types.WORKFLOW_DATA_TYPE.WFDT_STRING);
contactStateParameter.AppendFormat("<attributeid>{0}</attributeid>",
contactStateId);
contactStateParameter.Append("<orderofevaluation>0</orderofevaluation>");
contactStateParameter.Append("<name>Contact Address1 StateOrProvince</name>");
contactStateParameter.Append("<description>Parameter for the state the contact resides in</description>");
contactStateParameter.Append("</wfparameter>");
StringBuilder washingtonParameter = new StringBuilder("<wfparameter>");
washingtonParameter.AppendFormat("<parameterid>{0}</parameterid>",
Guid.NewGuid().ToString());
washingtonParameter.AppendFormat("<conditionid>{0}</conditionid>",
gregorConditionId.ToString());
washingtonParameter.AppendFormat("<parentid>{0}</parentid>",
equalsParameterId.ToString());
washingtonParameter.AppendFormat("<parametertypecode>{0}</parametertypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PARAMETER_TYPE.WFPM_VALUE);
washingtonParameter.AppendFormat("<datatype>{0}</datatype>",
Microsoft.Crm.Platform.Types.WORKFLOW_DATA_TYPE.WFDT_STRING);
washingtonParameter.Append("<orderofevaluation>2</orderofevaluation>");
washingtonParameter.Append("<value>WA</value>");
washingtonParameter.Append("<name>WA State</name>");
washingtonParameter.Append("<description>Parameter for WA state literal</description>");
washingtonParameter.Append("</wfparameter>");
// Create the XML string for a rule to create a task for Deepak
Guid deepakRuleId = Guid.NewGuid();
Guid deepakStepId = Guid.NewGuid();
StringBuilder deepakRuleXml = new StringBuilder("<wfrule>");
deepakRuleXml.AppendFormat("<ruleid>{0}</ruleid>",
deepakRuleId.ToString());
deepakRuleXml.AppendFormat("<stepid>{0}</stepid>",
initialStepId.ToString());
deepakRuleXml.AppendFormat("<nextstepid>{0}</nextstepid>",
deepakStepId.ToString());
deepakRuleXml.Append("<orderofevaluation>2</orderofevaluation>");
deepakRuleXml.Append("<name>E-mail Deepak Rule</name>");
deepakRuleXml.Append("<description>Default Rule: Create a task for Deepak</description>");
deepakRuleXml.Append("</wfrule>");
// Create the XML string for a step for Gregor's task creation
StringBuilder gregorStepXml = new StringBuilder("<wfstep>");
gregorStepXml.AppendFormat("<stepid>{0}</stepid>",
gregorStepId.ToString());
gregorStepXml.AppendFormat("<processid>{0}</processid>",
processId.ToString());
gregorStepXml.Append("<name>E-mail Gregor Step</name>");
gregorStepXml.Append("<description>Step to create a task for Gregor</description>");
gregorStepXml.Append("</wfstep>");
// Create the XML string for a step for Deepak's task creation
StringBuilder deepakStepXml = new StringBuilder("<wfstep>");
deepakStepXml.AppendFormat("<stepid>{0}</stepid>",
deepakStepId.ToString());
deepakStepXml.AppendFormat("<processid>{0}</processid>",
processId.ToString());
deepakStepXml.Append("<name>E-mail Deepak Step</name>");
deepakStepXml.Append("<description>Step to create a task for Deepak</description>");
deepakStepXml.Append("</wfstep>");
// Create XML strings for the action and action parameter to make a task for Gregor
Guid gregorActionId = Guid.NewGuid();
StringBuilder gregorActionXml = new StringBuilder("<wfaction>");
gregorActionXml.AppendFormat("<actionid>{0}</actionid>",
gregorActionId.ToString());
gregorActionXml.AppendFormat("<stepid>{0}</stepid>",
gregorStepId.ToString());
gregorActionXml.AppendFormat("<actiontypecode>{0}</actiontypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_ACTION_TYPE.WFAT_CREATE_ACTIVITY);
gregorActionXml.Append("<orderofexecution>1</orderofexecution>");
gregorActionXml.AppendFormat("<errorhandler>{0}</errorhandler>",
Microsoft.Crm.Platform.Types.WORKFLOW_ERROR_HANDLER_LEVEL.WFEH_WARNING);
gregorActionXml.Append("<name>Gregor Action</name>");
gregorActionXml.Append("<description>Create a task for Gregor</description>");
gregorActionXml.Append("</wfaction>");
StringBuilder gregorTaskXml = new StringBuilder("<activity>");
gregorTaskXml.AppendFormat("<scheduledstart>{0}</scheduledstart>",
System.DateTime.Now.AddDays(1).ToString("s"));
gregorTaskXml.Append("<subject>A new contact for your review</subject>");
gregorTaskXml.Append("<description>A new contact, &firstname; &lastname; ");
gregorTaskXml.Append(", has been created in WA</description>");
gregorTaskXml.AppendFormat("<ownerid type='{0}'>{1}</ownerid>",
Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.ToString(),
gregorId);
gregorTaskXml.AppendFormat("<activitytypecode>{0}</activitytypecode>",
Microsoft.Crm.Platform.Types.ObjectType.otActivity);
gregorTaskXml.Append("</activity>");
gregorTaskXml = gregorTaskXml.Replace("<", "<").Replace(">", ">");
Guid gregorTaskParamId = Guid.NewGuid();
StringBuilder gregorTaskParamXml = new StringBuilder("<wfparameter>");
gregorTaskParamXml.AppendFormat("<parameterid>{0}</parameterid>",
gregorTaskParamId.ToString());
gregorTaskParamXml.AppendFormat("<actionid>{0}</actionid>",
gregorActionId.ToString());
gregorTaskParamXml.AppendFormat("<parametertypecode>{0}</parametertypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PARAMETER_TYPE.WFPM_VALUE);
gregorTaskParamXml.AppendFormat("<datatype>{0}</datatype>",
Microsoft.Crm.Platform.Types.WORKFLOW_DATA_TYPE.WFDT_XML);
gregorTaskParamXml.Append("<orderofevaluation>1</orderofevaluation>");
gregorTaskParamXml.AppendFormat("<value>{0}</value>",
gregorTaskXml.ToString());
gregorTaskParamXml.Append("<name>Gregor Task</name>");
gregorTaskParamXml.Append("<description>Parameter containing the task XML for Gregor</description>");
gregorTaskParamXml.Append("</wfparameter>");
StringBuilder gregorFirstNameParamXml = new StringBuilder("<wfparameter>");
gregorFirstNameParamXml.AppendFormat("<parameterid>{0}</parameterid>",
Guid.NewGuid().ToString());
gregorFirstNameParamXml.AppendFormat("<parentid>{0}</parentid>",
gregorTaskParamId.ToString());
gregorFirstNameParamXml.AppendFormat("<actionid>{0}</actionid>",
gregorActionId.ToString());
gregorFirstNameParamXml.AppendFormat("<parametertypecode>{0}</parametertypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PARAMETER_TYPE.WFPM_PROPERTY);
gregorFirstNameParamXml.AppendFormat("<datatype>{0}</datatype>",
Microsoft.Crm.Platform.Types.WORKFLOW_DATA_TYPE.WFDT_STRING);
gregorFirstNameParamXml.AppendFormat("<attributeid>{0}</attributeid>",
contactFirstNameId);
gregorFirstNameParamXml.Append("<name>firstname</name>");
gregorFirstNameParamXml.Append("<orderofevaluation>1</orderofevaluation>");
gregorFirstNameParamXml.Append("</wfparameter>");
StringBuilder gregorLastNameParamXml = new StringBuilder("<wfparameter>");
gregorLastNameParamXml.AppendFormat("<parameterid>{0}</parameterid>",
Guid.NewGuid().ToString());
gregorLastNameParamXml.AppendFormat("<parentid>{0}</parentid>",
gregorTaskParamId.ToString());
gregorLastNameParamXml.AppendFormat("<actionid>{0}</actionid>",
gregorActionId.ToString());
gregorLastNameParamXml.AppendFormat("<parametertypecode>{0}</parametertypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PARAMETER_TYPE.WFPM_PROPERTY);
gregorLastNameParamXml.AppendFormat("<datatype>{0}</datatype>",
Microsoft.Crm.Platform.Types.WORKFLOW_DATA_TYPE.WFDT_STRING);
gregorLastNameParamXml.AppendFormat("<attributeid>{0}</attributeid>",
contactLastNameId);
gregorLastNameParamXml.Append("<name>lastname</name>");
gregorLastNameParamXml.Append("<orderofevaluation>2</orderofevaluation>");
gregorLastNameParamXml.Append("</wfparameter>");
// Create XML strings for the action and action parameter needed to
// make a task for Deepak
Guid deepakActionId = Guid.NewGuid();
StringBuilder deepakActionXml = new StringBuilder("<wfaction>");
deepakActionXml.AppendFormat("<actionid>{0}</actionid>",
deepakActionId.ToString());
deepakActionXml.AppendFormat("<stepid>{0}</stepid>",
deepakStepId.ToString());
deepakActionXml.AppendFormat("<actiontypecode>{0}</actiontypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_ACTION_TYPE.WFAT_CREATE_ACTIVITY);
deepakActionXml.Append("<orderofexecution>1</orderofexecution>");
deepakActionXml.AppendFormat("<errorhandler>{0}</errorhandler>",
Microsoft.Crm.Platform.Types.WORKFLOW_ERROR_HANDLER_LEVEL.WFEH_WARNING);
deepakActionXml.Append("<name>Deepak Action</name>");
deepakActionXml.Append("<description>Create task for Deepak</description>");
deepakActionXml.Append("</wfaction>");
StringBuilder deepakTaskXml = new StringBuilder("<activity>");
deepakTaskXml.AppendFormat("<scheduledstart>{0}</scheduledstart>",
System.DateTime.Now.AddDays(1).ToString("s"));
deepakTaskXml.Append("<subject>New contact for your review</subject>");
deepakTaskXml.Append("<description>A new contact, &firstname; &lastname;");
deepakTaskXml.Append(", has been created.</description>");
deepakTaskXml.AppendFormat("<ownerid type='{0}'>{1}</ownerid>",
Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.ToString(),
deepakId);
deepakTaskXml.AppendFormat("<activitytypecode>{0}</activitytypecode>",
Microsoft.Crm.Platform.Types.ObjectType.otActivity);
deepakTaskXml.Append("</activity>");
deepakTaskXml = deepakTaskXml.Replace("<", "<").Replace(">", ">");
Guid deepakTaskParamId = Guid.NewGuid();
StringBuilder deepakTaskParamXml = new StringBuilder("<wfparameter>");
deepakTaskParamXml.AppendFormat("<parameterid>{0}</parameterid>",
deepakTaskParamId.ToString());
deepakTaskParamXml.AppendFormat("<actionid>{0}</actionid>",
deepakActionId.ToString());
deepakTaskParamXml.AppendFormat("<parametertypecode>{0}</parametertypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PARAMETER_TYPE.WFPM_VALUE);
deepakTaskParamXml.AppendFormat("<datatype>{0}</datatype>",
Microsoft.Crm.Platform.Types.WORKFLOW_DATA_TYPE.WFDT_XML);
deepakTaskParamXml.Append("<orderofevaluation>1</orderofevaluation>");
deepakTaskParamXml.AppendFormat("<value>{0}</value>",
deepakTaskXml.ToString());
deepakTaskParamXml.Append("<name>Deepak Task</name>");
deepakTaskParamXml.Append("<description>Parameter containing the task XML for Deepak</description>");
deepakTaskParamXml.Append("</wfparameter>");
StringBuilder deepakFirstNameParamXml = new StringBuilder("<wfparameter>");
deepakFirstNameParamXml.AppendFormat("<parameterid>{0}</parameterid>",
Guid.NewGuid().ToString());
deepakFirstNameParamXml.AppendFormat("<parentid>{0}</parentid>",
deepakTaskParamId.ToString());
deepakFirstNameParamXml.AppendFormat("<actionid>{0}</actionid>",
deepakActionId.ToString());
deepakFirstNameParamXml.AppendFormat("<parametertypecode>{0}</parametertypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PARAMETER_TYPE.WFPM_PROPERTY);
deepakFirstNameParamXml.AppendFormat("<datatype>{0}</datatype>",
Microsoft.Crm.Platform.Types.WORKFLOW_DATA_TYPE.WFDT_STRING);
deepakFirstNameParamXml.AppendFormat("<attributeid>{0}</attributeid>",
contactFirstNameId);
deepakFirstNameParamXml.Append("<name>firstname</name>");
deepakFirstNameParamXml.Append("<orderofevaluation>1</orderofevaluation>");
deepakFirstNameParamXml.Append("</wfparameter>");
StringBuilder deepakLastNameParamXml = new StringBuilder("<wfparameter>");
deepakLastNameParamXml.AppendFormat("<parameterid>{0}</parameterid>",
Guid.NewGuid().ToString());
deepakLastNameParamXml.AppendFormat("<parentid>{0}</parentid>",
deepakTaskParamId.ToString());
deepakLastNameParamXml.AppendFormat("<actionid>{0}</actionid>",
deepakActionId.ToString());
deepakLastNameParamXml.AppendFormat("<parametertypecode>{0}</parametertypecode>",
Microsoft.Crm.Platform.Types.WORKFLOW_PARAMETER_TYPE.WFPM_PROPERTY);
deepakLastNameParamXml.AppendFormat("<datatype>{0}</datatype>",
Microsoft.Crm.Platform.Types.WORKFLOW_DATA_TYPE.WFDT_STRING);
deepakLastNameParamXml.AppendFormat("<attributeid>{0}</attributeid>",
contactLastNameId);
deepakLastNameParamXml.Append("<name>lastname</name>");
deepakLastNameParamXml.Append("<orderofevaluation>2</orderofevaluation>");
deepakLastNameParamXml.Append("</wfparameter>");
// Put all the XML strings in the process object
StringBuilder actionParams = new StringBuilder("<wfparameters>");
actionParams.Append(gregorTaskParamXml);
actionParams.Append(gregorFirstNameParamXml);
actionParams.Append(gregorLastNameParamXml);
actionParams.Append(deepakTaskParamXml);
actionParams.Append(deepakFirstNameParamXml);
actionParams.Append(deepakLastNameParamXml);
actionParams.Append("</wfparameters>");
oProcess.Steps = String.Format("<wfsteps>{0}{1}{2}</wfsteps>",
initialStepXml.ToString(), gregorStepXml.ToString(),
deepakStepXml.ToString());
oProcess.Rules = String.Format("<wfrules>{0}{1}</wfrules>",
gregorRuleXml.ToString(), deepakRuleXml.ToString());
oProcess.Conditions = String.Format("<wfconditions>{0}</wfconditions>",
gregorConditionXml.ToString());
oProcess.ConditionParameters = String.Format("<wfparameters>{0}{1}{2}</wfparameters>",
equalsParameter.ToString(),
contactStateParameter.ToString(),
washingtonParameter.ToString());
oProcess.Actions = String.Format("<wfactions>{0}{1}</wfactions>",
gregorActionXml.ToString(),
deepakActionXml.ToString());
oProcess.ActionParameters = actionParams.ToString();
// Create the workflow process with all of its elements
strProcessId = process.CreateAll(userAuth, oProcess);
}
catch (System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = String.Concat("ErrorMessage: ", err.Message, " ",
err.Detail.OuterXml, " Source: ", err.Source);
}
Requirements
Namespace: Microsoft.Crm.Platform.Proxy
Assembly: Microsoft.Crm.Platform.Proxy.dll
See Also