Custom Workflow Input and Output Parmeters in CRM
Hi,
Today I got a requirement to create a task and assign it to the Manager of the Owner on the Parent Record. We can easily get the Owner value in the system workflow but not the Manager of the owner.
For this I had to write a custom workflow which will take Owner value as an Input Parameter and returns Manager of the Owner as an Output Parameter.
Here is the way to declare Input and Output Parameter in a Custom Workflow.
/// <summary>
/// Input Argument - SystemUser
/// </summary>
[RequiredArgument]
[Input("User")]
[ReferenceTarget("systemuser")]
public InArgument<EntityReference> User { get; set; }
/// <summary>
/// Output Arugument - Manager of the user.
/// </summary>
[Output("Manager of the user")]
[ReferenceTarget("systemuser")]
public OutArgument<EntityReference> Manager { get; set; }
And this the below code in the Workflow Execute Method.
Entity entityUser = service.Retrieve("systemuser", erfUser.Id, new ColumnSet(newstring[] { "parentsystemuserid" }));
Manager.Set(executionContext, (EntityReference)entityUser.Attributes["parentsystemuserid"]);
After this, just build your project and deploy it in CRM and use the same in the system workflow by passing the Owner value and it will give the Manager of the owner.
In the same way, we can using CRM Custom Workflow for many business operations by using Input and Output Parameters.
Today I got a requirement to create a task and assign it to the Manager of the Owner on the Parent Record. We can easily get the Owner value in the system workflow but not the Manager of the owner.
For this I had to write a custom workflow which will take Owner value as an Input Parameter and returns Manager of the Owner as an Output Parameter.
Here is the way to declare Input and Output Parameter in a Custom Workflow.
/// <summary>
/// Input Argument - SystemUser
/// </summary>
[RequiredArgument]
[Input("User")]
[ReferenceTarget("systemuser")]
public InArgument<EntityReference> User { get; set; }
/// <summary>
/// Output Arugument - Manager of the user.
/// </summary>
[Output("Manager of the user")]
[ReferenceTarget("systemuser")]
public OutArgument<EntityReference> Manager { get; set; }
And this the below code in the Workflow Execute Method.
// Get the Manager of the user.
EntityReference erfUser = User.Get<EntityReference>(executionContext);Entity entityUser = service.Retrieve("systemuser", erfUser.Id, new ColumnSet(newstring[] { "parentsystemuserid" }));
Manager.Set(executionContext, (EntityReference)entityUser.Attributes["parentsystemuserid"]);
After this, just build your project and deploy it in CRM and use the same in the system workflow by passing the Owner value and it will give the Manager of the owner.
In the same way, we can using CRM Custom Workflow for many business operations by using Input and Output Parameters.
I Hope this helps
Happy CRM'ing!
No comments:
Post a Comment
Note: only a member of this blog may post a comment.