web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Set a particular business process flow on create with web api

(0) ShareShare
ReportReport
Posted on by

Hi all,

I have an incident entity with 2 business process flows and a set of customized buttons on account entity that will automatically create an incident using the web api.
The problem I am having is that depending on which button the user clicks the corresponding bpf should be applied to that record.
I know I could switch to the correct process using setActiveProcess when the record is opened but I would like to avoid it loading twice.
I have been reading this which states:

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 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.

But I can't seem to figure out how this should be done, I have tried setting the value for processid like this:

entity["processid@odata.bind"] = "/workflows(" + businessProcessId + ")"; //This throws bad request
entity.processid = businessProcessId; //Finishes successfully but the correct BPF is not loaded when opening the record


Any help on how to solve this will be greatly appreciated

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Jon,

    I had a similar issue a few days ago and I think that when trying to set the processid in a plug-in registered on created I got an error saying that the stageid is incorrect.

    I gave up on that approach and used the SetProcessRequest in a Plug-in set on Post Create- see msdn.microsoft.com/.../microsoft.crm.sdk.messages.setprocessrequest.aspx. This worked fine.

    Hope this helps,

    Radu

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Radu,

    According to the documentation this way is no longer viable in version 9.x have you tried this on the 9.x versions ? 

    6036.Capture123.PNG

    If it helps anyone I found a way to do this with js without having to refresh the record onload

    //Call this after I have created the incident via web api request on account form
    var entity = {}; entity.bpf_name = title; entity["bpf_incidentid@odata.bind"] = "/incidents(" + incidentId + ")"; entity["processid@odata.bind"] = "/workflows(" + processId + ")"; var req = new XMLHttpRequest();
    //This uses the entity created with the business process flow req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/new_name_of_bpfs", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 204) {
    //Open previously created incident after it is set to use the correct process
    Xrm.Utility.openEntityForm("incident", incidentId); } } else { //HANDLE ERROR } }; req.send(JSON.stringify(entity));


  • Radu Chiribelea Profile Picture
    6,667 on at

    Hi Jon,

    Thanks for the heads up. I did the plug-in on 8.2.

    Nice find.

    Regards,

    Radu

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans