Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Regarding changing BPF

Posted on by Microsoft Employee

i am trying to change BPF whole process based on field value it is working for only one value(NO) for others it is not changing here is my code pls suggest. for selecting No it is changing for Yes & Waiting it is not changing

function onload() {

// If not new Case form
// if (Xrm.Page.ui.getFormType() != 1) {
// Read Origin Option text
var origin = Xrm.Page.data.entity.attributes.get("new_aprroving");
// if (origin && origin.getText()) {
var caseOrigin = origin.getText();
alert(caseOrigin);
// Get Business process flow id
var processFlow1Id = "7B02E72B-44F0-49D7-975D-6C0B20B2DFDE";
var processFlow2Id = "4BF02651-9A0A-48CC-9AAF-2B1E07A3DFC0";
var processFlow3Id = "46144F08-5B03-442B-A9C5-E3AFBB957EF2";
// Get Current Active Process Id
var activeProcess = Xrm.Page.data.process.getActiveProcess();
var currProcessId = activeProcess.getId();
if (caseOrigin.toLowerCase() == "yes") {
alert(currProcessId);
// Change the process only if current Active Process not the Target one
if (currProcessId.toLowerCase() != processFlow1Id.toLowerCase()) {
alert("yes1");
// Switch to the “Process Flow 1”
Xrm.Page.data.process.setActiveProcess(processFlow1Id, myCallBack);
}
} else if (caseOrigin.toLowerCase() == "no") {
// Change the process only if current Active Process not the Target one
if (currProcessId.toLowerCase() != processFlow2Id.toLowerCase()) {
// Switch to the “Process Flow 2”
Xrm.Page.data.process.setActiveProcess(processFlow2Id, myCallBack);
}
else if (caseOrigin.toLowerCase() == "waiting") {
// Change the process only if current Active Process not the Target one
if (currProcessId.toLowerCase() != processFlow3Id.toLowerCase()) {
// Switch to the “Process Flow 3”
Xrm.Page.data.process.setActiveProcess(processFlow3Id, myCallBack);
}
}
// Call back function post Process flow switch
function myCallBack(response) {
if (response == "success") {
alert("BPF changed !!!");
// Save the form
Xrm.Page.data.entity.save();
}
else {
alert("Error changing BPF!!!");
}
}
}
}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Regarding changing BPF

    thanks ravi its working fine now

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Regarding changing BPF

    Hi Manikanta,

    You have wrong braces in your script. Basically you have the callback method inside the no  block.

    Use this script-

    --------------------------------------------------------------

    function onload() {

       // If not new Case form

       // if (Xrm.Page.ui.getFormType() != 1) {

       // Read Origin Option text

       var origin = Xrm.Page.data.entity.attributes.get("new_aprroving");

       // if (origin && origin.getText()) {

       var caseOrigin = origin.getText();

       alert(caseOrigin);

       // Get Business process flow id

       var processFlow1Id = "7B02E72B-44F0-49D7-975D-6C0B20B2DFDE";

       var processFlow2Id = "4BF02651-9A0A-48CC-9AAF-2B1E07A3DFC0";

       var processFlow3Id = "46144F08-5B03-442B-A9C5-E3AFBB957EF2";

       // Get Current Active Process Id

       var activeProcess = Xrm.Page.data.process.getActiveProcess();

       var currProcessId = activeProcess.getId();

       if (caseOrigin.toLowerCase() == "yes")

       {

           alert(currProcessId);

           // Change the process only if current Active Process not the Target one

           if (currProcessId.toLowerCase() != processFlow1Id.toLowerCase()) {

               alert("yes1");

               // Switch to the “Process Flow 1”

               Xrm.Page.data.process.setActiveProcess(processFlow1Id, myCallBack);

           }

       }

       else if (caseOrigin.toLowerCase() == "no") {

           // Change the process only if current Active Process not the Target one

           if (currProcessId.toLowerCase() != processFlow2Id.toLowerCase()) {

               alert("no");

               // Switch to the “Process Flow 2”

               Xrm.Page.data.process.setActiveProcess(processFlow2Id, myCallBack);

           }

       }

       else if (caseOrigin.toLowerCase() == "waiting") {

           // Change the process only if current Active Process not the Target one

           if (currProcessId.toLowerCase() != processFlow3Id.toLowerCase()) {

               alert("waiting");

               // Switch to the “Process Flow 3”

               Xrm.Page.data.process.setActiveProcess(processFlow3Id, myCallBack);

           }

       }

       // Call back function post Process flow switch

       function myCallBack(response) {

           if (response == "success") {

               alert("BPF changed !!!");

               // Save the form

               Xrm.Page.data.entity.save();

           }

           else {

               alert("Error changing BPF!!!");

           }

       }

    }

    ------------------------------------------------------------------

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Regarding changing BPF

    yes manually i can change process

  • Andreas Cieslik Profile Picture
    Andreas Cieslik 9,265 on at
    RE: Regarding changing BPF

    Is it possible to start and switch the process with the build in switch process button by clicking the Process button on the command toolbar on the record?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Regarding changing BPF

    i changed the flowid1 with flid2 (means the variables r changed with one other like for NO ID1 for Yes ID2) and tried this time for NO also it havent executed  

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Regarding changing BPF

    All process r in active

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Regarding changing BPF

    1452.aaa.jpg

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Regarding changing BPF

    Have you activated all the three business process flows?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Regarding changing BPF

    yes i took from there first and then i tried with alerted one also both r same

       if (caseOrigin.toLowerCase() == "yes") {

           alert(currProcessId);

           // Change the process only if current Active Process not the Target one

           if (currProcessId != processFlow1Id) {

              alert("yes1");

    if i change to yes it is executing this alert YES1 also so which means the condition (currProcessId != processFlow1Id) is true

    next line is Xrm.Page.data.process.setActiveProcess(processFlow1Id, myCallBack); here setting process it is not executing

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Regarding changing BPF

    Please go to Settings --> Processes.

    Open the Business Process Flow and make sure the GUID is the same which appears in which URL.

    The id is between %7b and %7d as shown in red colour in the screenshot below.

    158066.1.PNG

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans