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
Hi @ Gautam i tried the JS thing it isn't working can you tell me any other way
Thank you Goutam, its exactly what I need. Its really a huge designe change in CRM concerning the BPF.
Hello,
You might be know that now every BPF having an entity with same BPF name. In the BPF entity you should find the opportunity lookup . You can navigate to customization-> Customize the system-> and then expand the BPF entity -> Fields and find the Opportunity lookup schema name.
Guid OppId = ((EntityReference)targetEntity.Attributes["BPFLookupOppFieldId"]).Id;
In addition you can also try with JavaScript, have a look here sample custom validation.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156