Answered by:
CRM 2011 Online - Executing a workflow on an entity with 1:N or N:N relationship

Question
-
We're using CRM 2011 Online by the way (I know this is possible in the on-premise version)
For example
1. a workflow that updates all associated invoices when the value of an order changes.
2. A workflow that closes all activities associated with an opportunity, when the opportunity is won/lost.
I've been trying to find away to do this, but this only seems to be possible by using a Custom Workflow Activity, and the best info I can find tells me that Custom Workflow activities are not supported in CRM 2011 online. I'm sure there must be a workaround, can anyone point me in the right direction to do this please?
Friday, October 21, 2011 1:50 PM
Answers
-
Hi,Adding further notes, yes custom workflow assemblies are not supported in CRM 2011 version and if flowjob has mentioned correctly that developing plugin is the right approch in your case. For your first scenerio you should develop a plugin that will be registered on SetStateDynamicEntity message in Pre-Operation stage for Sales Order entity in Synchornous execution , in plugin code you can retrieve all assosiated invoices and then update them as per required. Sample code would be:
if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference &&
((EntityReference)context.InputParameters["EntityMoniker"]).LogicalName == "salesorder") {
switch (context.MessageName)
{// Check if entity status is changed
case "SetStateDynamicEntity":#region Configuraiton Activation Safe Check
if (context.InputParameters.Contains("State"))
{OptionSetValue StateValue = (OptionSetValue)context.InputParameters["State"]).Value;OptionSetValue StatusValue = (OptionSetValue)context.InputParameters["Status"]).Value;// Check if order status value is updated as per required then retrieve all assosiated invoices and update them
}
}
}2. Develop a plugin and register two steps on Opportunity entity for message Win and Lose in Pre-Operation and Syncrhonous exection, in you plugin code retrieve all open activities using CrmService.RetrieveMultiple request and then close the activities via SetState webservice method. In plugin code you can use the following sample code:Entity opptyClose = (Entity)context.InputParameters["OpportunityClose"];
EntityReference opptyRef = opptyClose["opportunityid"] as EntityReference;
Guid opptyId = opptyRef.id;
For plugin development basics you may also refer: http://crmconsultancy.wordpress.com/2010/10/25/plugins-in-crm-2011/
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Proposed as answer by Jehanzeb.Javeed Sunday, October 23, 2011 9:52 PM
- Edited by Jehanzeb.Javeed Sunday, October 23, 2011 9:54 PM Added Link
- Marked as answer by BusinessWorks Monday, October 24, 2011 8:54 AM
Sunday, October 23, 2011 9:52 PM
All replies
-
Custom workflow activities are not supported for CRM Online, but plugins are. For the 1st example register on the Update message for the order entity. Use "filtering attributes" when registering so that it will only trigger when the specific attribute changes. For the 2nd example register your plugin(s) on "Win" or "Lose" messages for the opportunity.
- Edited by flowjob Saturday, October 22, 2011 2:17 PM
Saturday, October 22, 2011 2:12 PM -
Hi,Adding further notes, yes custom workflow assemblies are not supported in CRM 2011 version and if flowjob has mentioned correctly that developing plugin is the right approch in your case. For your first scenerio you should develop a plugin that will be registered on SetStateDynamicEntity message in Pre-Operation stage for Sales Order entity in Synchornous execution , in plugin code you can retrieve all assosiated invoices and then update them as per required. Sample code would be:
if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference &&
((EntityReference)context.InputParameters["EntityMoniker"]).LogicalName == "salesorder") {
switch (context.MessageName)
{// Check if entity status is changed
case "SetStateDynamicEntity":#region Configuraiton Activation Safe Check
if (context.InputParameters.Contains("State"))
{OptionSetValue StateValue = (OptionSetValue)context.InputParameters["State"]).Value;OptionSetValue StatusValue = (OptionSetValue)context.InputParameters["Status"]).Value;// Check if order status value is updated as per required then retrieve all assosiated invoices and update them
}
}
}2. Develop a plugin and register two steps on Opportunity entity for message Win and Lose in Pre-Operation and Syncrhonous exection, in you plugin code retrieve all open activities using CrmService.RetrieveMultiple request and then close the activities via SetState webservice method. In plugin code you can use the following sample code:Entity opptyClose = (Entity)context.InputParameters["OpportunityClose"];
EntityReference opptyRef = opptyClose["opportunityid"] as EntityReference;
Guid opptyId = opptyRef.id;
For plugin development basics you may also refer: http://crmconsultancy.wordpress.com/2010/10/25/plugins-in-crm-2011/
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Proposed as answer by Jehanzeb.Javeed Sunday, October 23, 2011 9:52 PM
- Edited by Jehanzeb.Javeed Sunday, October 23, 2011 9:54 PM Added Link
- Marked as answer by BusinessWorks Monday, October 24, 2011 8:54 AM
Sunday, October 23, 2011 9:52 PM