Hi all,
I have a requirement from the customer to implement a validation logic on the opportunity business process when we go from stage to another. The logic is complex so for that reason we cant do it in the businessflow editor. For that reason Il trying to implement a plugin on the BusinessProcessFlowInstance entity on the PreUpdate message to get the Previous stage id and the target stage id (Next one). I have no problem with stages ids, but I need to get the opportunity id related to the current Businessflow instance to retrieve data related to the opportunity for my validation logic requirement. So my question is : Haw to get the opportunity from the BusinessProcessFlowInstance plugin.
bellow : the plugin code that I start to implement :
namespace REA.Crm.Plugins.OpportunityPlugins
{
public class businessprocessflowinstancePlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
OrganizationServiceContext1 OrgServiceCntx = new OrganizationServiceContext1(service);
BusinessProcessFlowInstance targetEntity = ((Entity)context.InputParameters["Target"]).ToEntity<BusinessProcessFlowInstance>();
BusinessProcessFlowInstance preimage = ((Entity)context.PreEntityImages["preimage"]).ToEntity<BusinessProcessFlowInstance>();
Guid? PreviousActiveStage = GetPreviousActiveStageFromTraversedPath(preimage.TraversedPath);
Guid? TargetActiveStage = targetEntity.ProcessStageId;
tracingService.Trace("EntityID " + targetEntity.Entity1Id.ToString());
tracingService.Trace("EntityID " + targetEntity.Entity2Id.ToString());
tracingService.Trace("EntityID " + targetEntity.Entity3Id.ToString());
tracingService.Trace("EntityID " + targetEntity.Entity4Id.ToString());
tracingService.Trace("EntityID " + targetEntity.Entity5Id.ToString());
}
Guid? GetPreviousActiveStageFromTraversedPath(string TraversedPath)
{
Guid? PreviousActiveStage = null;
string[] splitedTraversedPath = TraversedPath.Split(',');
if (splitedTraversedPath.Length > 0)
PreviousActiveStage=Guid.Parse(splitedTraversedPath[splitedTraversedPath.Length].ToString());
return PreviousActiveStage;
}
}
}
*This post is locked for comments
I have the same question (0)