Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Set BPF OnCreate of Entity Record from Angular web Page in CRM 9.0

Posted on by 2,665

Hi All,

I am using below Plugin code to apply BPF based on field value on Case entity on create, its working fine if am creating record from CRM. But when record gets created from Angular web page side then its not placing with the particular BPF instead the record is showing with default BPF .

Entity incident = null;

if (executionContext.InputParameters.Contains("Target") && (executionContext.InputParameters["Target"] is Entity))

incident = (Entity)executionContext.InputParameters["Target"];

var incidentDetails = (from tra in organizationServiceContext.CreateQuery("incident")

where (Guid)tra["incidentid"] == incident.Id

select new

{

Id = tra.Contains("incidentid") ? (Guid)tra["incidentid"] : Guid.Empty,

InteractionType = tra.Contains("mdc_interactiontype") ? ((EntityReference)tra["mdc_interactiontype"]).Name : string.Empty

}).FirstOrDefault();

if (incidentDetails.InteractionType.ToLower() == "conflict of interest")

{

SetProcessRequest request = new SetProcessRequest();

request.Target = new EntityReference("incident", incident.Id);

// THE BELOW POINTS TO THE CORRECT GUID OF THE BUSINESS PROCESS FLOW

request.NewProcess = new EntityReference("workflow", new Guid("7A538A01-DD47-4335-833E-11E8F9BAD906"));

organizationService.Execute(request);

}

else if (incidentDetails.InteractionType.ToLower() == "gift & entertainment")

{

SetProcessRequest request = new SetProcessRequest();

request.Target = new EntityReference("incident", incident.Id);

// THE BELOW POINTS TO THE CORRECT GUID OF THE BUSINESS PROCESS FLOW

request.NewProcess = new EntityReference("workflow", new Guid("57E8BC82-F936-4CBA-B6C6-18A7C3E270A2"));

organizationService.Execute(request);

What could be the issue , Please let me know.

Thanks,

Jharana

  • Jharana Baliyar Singh Profile Picture
    Jharana Baliyar Singh 2,665 on at
    RE: Set BPF OnCreate of Entity Record from Angular web Page in CRM 9.0

    No Bipin , every time the record is asociating with 2 processes .I ahve tried with retrieving processes & checked with condition in foreach loop & then set the process but its not working.

  • Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Set BPF OnCreate of Entity Record from Angular web Page in CRM 9.0

    Hi,

    Did it worked ?

    Please mark my answer verified if i were helpful

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Set BPF OnCreate of Entity Record from Angular web Page in CRM 9.0

    Hi,

    Setprocessrequest can no longer be used instead use processid field to set default bpf see below article.

    docs.microsoft.com/.../model-business-process-flows

    You can override the default logic of business process flows getting applied automatically to new entity records. To do so, set the ProcessId attribute of the entity to one of the following values while creating a new entity record:

    Set to Guid.Empty to skip setting a business process flow for new entity records. You might want to do that if you are bulk creating entity records, but don't want business process flow to be applied to them.

    Set it to a specific business process flow entity (as an entity reference). In this case, the system will apply the specified business process flow instead of the default logic.

    If you do not set a value for the ProcessId attribute while creating a new entity record, the system will apply the default logic as explained earlier.

    Please mark my answer verified if i were helpful

  • Jharana Baliyar Singh Profile Picture
    Jharana Baliyar Singh 2,665 on at
    RE: Set BPF OnCreate of Entity Record from Angular web Page in CRM 9.0

    Hi Bipin,

    I have checked with process & created case record from console still its not reflecting the correct BPF but in trace log i am getting the incident id all rcoming fine.

    Please find the below code am using

    Entity incident = null;

               if (executionContext.InputParameters.Contains("Target") && (executionContext.InputParameters["Target"] is Entity))

                   incident = (Entity)executionContext.InputParameters["Target"];

               tracingService.Trace($"Get Incident Id : " + incident.Id);

               if (executionContext.Depth <= 3)

               {

                   tracingService.Trace($"Depth is less than 3");

                   //EntityReference categoryType = null;

                   //Entity createPostImage = (Entity)executionContext.PostEntityImages["ConflictofInterestPostImage"];

                   //if (createPostImage.Contains("mdc_interactiontype"))

                   //    categoryType = (EntityReference)createPostImage["mdc_interactiontype"];

                   try

                   {

                       tracingService.Trace($"Triggering here....");

                       organizationServiceContext.ClearChanges();

                       //get the values of the case

                       var incidentDetails = (from tra in organizationServiceContext.CreateQuery("incident")

                                             where (Guid)tra["incidentid"] == incident.Id

                                              select new

                                              {

                                                  Id = tra.Contains("incidentid") ? (Guid)tra["incidentid"] : Guid.Empty,

                                                  InteractionType = tra.Contains("mdc_interactiontype") ? ((EntityReference)tra["mdc_interactiontype"]).Name : string.Empty

                                              }).FirstOrDefault();

                       tracingService.Trace($"Get Incident : " + incident.Id);

                       if (incidentDetails.InteractionType.ToLower() == "conflict of interest")

                       {

                           SetProcessRequest request = new SetProcessRequest();

                           request.Target = new EntityReference("incident", incident.Id);

                           // THE BELOW POINTS TO THE CORRECT GUID OF THE BUSINESS PROCESS FLOW

                           request.NewProcess = new EntityReference("process", Guid.Parse("7A538A01-DD47-4335-833E-11E8F9BAD906"));

                           organizationService.Execute(request);

                           tracingService.Trace($"COI BPF gets updated here....");

                       }

                       else if (incidentDetails.InteractionType.ToLower() == "gift & entertainment")

                       {

                           SetProcessRequest request = new SetProcessRequest();

                           request.Target = new EntityReference("incident", incident.Id);

                           // THE BELOW POINTS TO THE CORRECT GUID OF THE BUSINESS PROCESS FLOW

                           request.NewProcess = new EntityReference("process", Guid.Parse("57E8BC82-F936-4CBA-B6C6-18A7C3E270A2"));

                           organizationService.Execute(request);

                           tracingService.Trace($"GE BPF gets updated here....");

                       }

                       UpdateReporterDetails(incident, tracingService);

                       tracingService.Trace($"Reporter Details Updated....");

                       try

                       {

                           if (executionContext.MessageName.ToUpper() == "UPDATE")

                           {

                               if (executionContext.InputParameters.Contains("Target") && executionContext.InputParameters["Target"] is Entity)

                               {

                                   Entity entity = (Entity)executionContext.InputParameters["Target"];

                                   if (entity.Contains("mdc_action") && entity["mdc_action"] != null)

                                   {

                                       OptionSetValue value = (OptionSetValue)entity.Attributes["mdc_action"];

                                       int action = value.Value;

                                       if (action == 755040000)    //Approved

                                       {

                                           //Move To Next Stage

                                           ChangeStage(tracingService, entity);

                                           tracingService.Trace($"Stage moved to next....");

                                       }

                                   }

                               }

                           }

                       }

    From Trace log in below :

    Get Incident Id : 8f2c207d-b3ea-ea11-a824-001dd8b70014

    Depth is less than 3

    Triggering here....

    Get Incident : 8f2c207d-b3ea-ea11-a824-001dd8b70014

    GE BPF gets updated here....

    ReporterName : 89 Al Hammadi

    Case has been Updated

    Reporter Details Updated....

    And checked in Advanced fiend with the Process entity like GE Group process entity then while am opening the record its showing Record is Unavailable error The requested record was not found or you do not have sufficient permission to view it.& by downloading log file showing the process id doesn't exist.

    Here always by default process am setting with different process so getting here 2 processes one is default & another one GE group process thats why always its taking default one.

    But how can i check the process condition to make apply on create id case.

    Thanks,

    Jharana

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Set BPF OnCreate of Entity Record from Angular web Page in CRM 9.0

    Hi,

    I think i have found out the issue in your code.

    req.NewProcess = new EntityReference("process", Guid.Parse("AEC906DF-5C10-490D-8D0E-E5620FAAE614"));

    you have passed workflow instead of process in NewProcess property.

    Please mark my answer verified if i were helpful

  • Jharana Baliyar Singh Profile Picture
    Jharana Baliyar Singh 2,665 on at
    RE: Set BPF OnCreate of Entity Record from Angular web Page in CRM 9.0

    Hi Bipin,

    I have checked with depth but still no luck..

    Thanks,

    Jharana

  • Jharana Baliyar Singh Profile Picture
    Jharana Baliyar Singh 2,665 on at
    RE: Set BPF OnCreate of Entity Record from Angular web Page in CRM 9.0

    Hi Bipin,

    I cant debug my code as its onpremise & in server vs is not available so only can check the code in console.

    Okay will check with context.depth<=3 .

    Thanks,

    Jharana

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Set BPF OnCreate of Entity Record from Angular web Page in CRM 9.0

    HI,

    Can you try debugging your plugin code.

    I am assuming you don't have depth check in your plugin correct?

    Add trace in your plugin and check log under settings->Plugin trace log .

    Please mark my answer verified if i were helpful

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans