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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

SetActiveProcess BPF does not load the current selected form

(0) ShareShare
ReportReport
Posted on by 215

Hello everyone,

.

For Account entity, I have created

  • 2 forms called : formA, formB
  • 2 business process flow (BPF)

On formA : I have a hanlder for OnLoad event which will set the correct BPF according to the Account type.

I use the standard function to set the active process :

Xrm.Page.data.process.setActiveProcess(processId, callbackFunction);

This works fine, when the function setActiveProcess is executed, the BPF is applied correctly and the form reloads to reflect the changes.

However, it doesn't work as expected in the following scenario

  1. The user opens the record with formB at the beginning
  2. Then user selects formA
  3. The script OnLoad on formA is executed -> setActiveProcess is called -> the form is reload

BUT, it loads formB instead formA, it should not be the case, the expected behavior is that it should reloads formA which is the current selected form, not formB (which is the previous one)

.

Has anyone experienced this issue yet? Is there any way that I could clear the 'cache' that stores the previous selected form?

I have Dynamics 365 Updates 2.2 installed.

.

Thanks for your help,

Kim Anh

*This post is locked for comments

I have the same question (0)
  • Anh Luu Profile Picture
    215 on at
    RE: SetActiveProcess BPF does not load the current selected form

    Hello Sreedhar Kashyap,

    .

    I guess that your POST url is not correct.

    It should be something like this : encodeURI(clientUrl + "/api/data/v8.0/SetProcess")

    .

    Cheers,

    Kim Anh

  • Community Member Profile Picture
    on at
    RE: SetActiveProcess BPF does not load the current selected form

    When i try to do the same using web api, getting below error

    ""Cannot find nested property 'Target' on the resource type 'Microsoft.Dynamics.CRM.incident'."

    Just FYI: I am setting business process on CASE entitiy not accounts.

    Below is the code:

        var clientUrl = Xrm.Page.context.getClientUrl();
        var req = new XMLHttpRequest()
        req.open("POST", encodeURI(clientUrl + "/api/data/v8.0/incidents"), true);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
    
        req.onreadystatechange = function () {
            if (this.readyState == 4 /* complete */) {
                req.onreadystatechange = null;
                if (this.status == 200) {
                    debugger;
                    OnSetActiveProcessSuccess(category);
                }
                else {
                    var error = JSON.parse(this.response).error;
                    alert(error.message);
                }
            }
        };
    
    
        var data = JSON.stringify({
            "Target": {
                "incidentid": caseid,
                "@odata.type": "Microsoft.Dynamics.CRM.incident"
            },
            "NewProcess": {
                "workflowid": processId,
                "@odata.type": "Microsoft.Dynamics.CRM.workflow"
            }
        });
        
        req.send(data);

    can you help me out?

    var clientUrl = Xrm.Page.context.getClientUrl();    var req = new XMLHttpRequest()    req.open("POST", encodeURI(clientUrl + "/api/data/v8.0/incidents"), true);    req.setRequestHeader("Accept", "application/json");    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");    req.setRequestHeader("OData-MaxVersion", "4.0");    req.setRequestHeader("OData-Version", "4.0");
        req.onreadystatechange = function () {        if (this.readyState == 4 /* complete */) {            req.onreadystatechange = null;            if (this.status == 200) {                debugger;                OnSetActiveProcessSuccess(category);            }            else {                var error = JSON.parse(this.response).error;                alert(error.message);            }        }    };

        var data = JSON.stringify({        "Target": {            "incidentid": caseid,            "@odata.type": "Microsoft.Dynamics.CRM.incident"        },        "NewProcess": {            "workflowid": processId,            "@odata.type": "Microsoft.Dynamics.CRM.workflow"        }    });    debugger;    req.send(data);

  • Community Member Profile Picture
    on at
    RE: SetActiveProcess BPF does not load the current selected form

    HI Anh,

    Can you please share code on how to call SetProcess on Web API from javascript, i am also having same issue.

  • Verified answer
    Anh Luu Profile Picture
    215 on at
    RE: SetActiveProcess BPF does not load the current selected form

    Thanks Alex.

    But using openEntityForm does not help here because the bug is exactly the behavior of the setActiveProcess function itself which auto reloads the form after it finishes :)

    .

    My workaround is : call the SetProcess action directly (using Web API) to set the process active :)

    Then reload the current selected form after the call success.

    {
    	"Target": {
    		"accountid" : accountId,
    		"@odata.type" : "Microsoft.Dynamics.CRM.account"
    	},
    	"NewProcess": {
    		"workflowid" : processId,
    		"@odata.type" : "Microsoft.Dynamics.CRM.workflow"
    	}
    }
  • ashlega Profile Picture
    34,477 on at
    RE: SetActiveProcess BPF does not load the current selected form

    Did you try using OpenEntityForm to open the form you need?

    msdn.microsoft.com/.../jj602956.aspx

    I think the behavior you are describing may have something to do with how/where Dynamics is caching "default" form selection (unlike in the previous versions, it's not updated on the server side right away.. so another option might be to give it a second or two after the form shows up up before calling setActiveProcess.. in that case, try using setTimeout, and call setActiveProcess there)

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans