Skip to main content

Notifications

Announcements

No record found.

Customer Service forum

How to Switch Business Process Flow automatically

Posted on by 40

Hi All,

I have around 30 or more business process flows and I cannot have all the processes in one design since there is a limitation in dynamics 365 on number of entities and conditions we can specify. I have therefore created a multiple business process flows which will be triggered on change of a field value. (application type as shown in the image below).

supposing: I wanted;

  1.  business process flow 1 to run/be active if the Application type is A
  2.  business process flow 2 to run/be active if the Application type is B
  3.  business process flow3 to run/be active if the Application type is C, D, E

I am just wondering if there is a way to automate this process using the out-of- box functionality or ISV solution. if not does it require a plugin or a JS to do this. Appreciate if someone could share your knowledge if you have come across such problems. A JS or ISV solution or anything will be helpful to me since I am fairly new to this environment.

pastedimage1565851158190v2.png

Thank you 

TPY

Categories:
  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: How to Switch Business Process Flow automatically

    Hi partner,

    Thanks so much for your recognition :-)

    It is possible to use different conditions to switch different BPF in your code, just follow your requirement.

    Have a nice day.

    Best Regards,

    Leo

  • TPY Profile Picture
    TPY 40 on at
    RE: How to Switch Business Process Flow automatically

    Thanks Leo, its working now,  i found an event handler for change process existed for this error to occur. Its working fine now, and thanks heaps for you help.

    Last thing, if i have to add one more if condition in the code to select a different business process with different id, would it work?

    Something like below; to switch between the two.

    pastedimage1566175931947v1.png

    It returned an error when i tried.

    Thank you, 

    TPY

  • Suggested answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: How to Switch Business Process Flow automatically

    Hi partner,

    1.The first error is unrelated to our "switchBPF" code because you added the method on the Onchange event not Onload event. So I think that you should check the methods which added in Onload event.

    2.I did not find any problem in your code, so did you select "Pass execution context as first parameter" when you add the method to event?

    pastedimage1565974187230v1.png

    Beacuse if you did not select this, "executionContext" will not be defined in your code.

    Hope it helps.

    Best Regards,

    Leo

  • TPY Profile Picture
    TPY 40 on at
    RE: How to Switch Business Process Flow automatically

    Hi Leo,

    I get these two errors. One, when opening  new  or refreshing an application page.

    Screen-Shot-2019_2D00_08_2D00_16-at-8.28.51-pm.png

    and this one when changing application type field.

    Screen-Shot-2019_2D00_08_2D00_16-at-8.29.10-pm.png

    Thank you heaps,

    TPY

  • TPY Profile Picture
    TPY 40 on at
    RE: How to Switch Business Process Flow automatically

    Hi Leo,

    I have checked the web resource and didn't find any other function by the name "change process".

    I have used the exact code that you sent and this script error is still there.

    In order for you to understand better, i have below screen shot showing where and how i have set the function on the form properties and field.

    Screen-Shot-2019_2D00_08_2D00_16-at-8.12.23-pm.png

    Screen-Shot-2019_2D00_08_2D00_16-at-8.11.59-pm.png

    Screen-Shot-2019_2D00_08_2D00_16-at-8.13.29-pm.pngScreen-Shot-2019_2D00_08_2D00_16-at-9.28.59-pm.png

    Thanks heaps,

    Regards

    TPY

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: How to Switch Business Process Flow automatically

    Hi partner,

    There is no such function named "changeprocess" in my code here, could you share you code or check it again?

    Best Regards,

    Leo

  • TPY Profile Picture
    TPY 40 on at
    RE: How to Switch Business Process Flow automatically

    Hi Leo,

    Thanks a lot for your feedback on the code and sending over the corrected one. I have used the same code in my environment and it returns the below script error which i have no clue of. Could you please advice what this is and why its popping on screen on creation of new application.

    Screen-Shot-2019_2D00_08_2D00_16-at-7.49.03-pm.png

    thank you heaps,

    Regards 

    TPY

  • Verified answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: How to Switch Business Process Flow automatically

    Hi partner,

    There are some error in your code.

    1. The "formceontext" you defined and used are different,use the same uppercase and lowercase letters.

    2.The Double quotation marks beside "Success" should be English half Angle symbol like others in your code.

    3.The variable "statuscode" is not defined in your code.

    4.Please make sure that all the fields you used in your code should be added into form.

    5.The function name "callBackFunction" are different between defined and used.

    6.gettext should change to "getText".

    7.We don't need to add %7b %7d between processid.

    8.If the action successfully change the BPF, the result is "success" not "Success".

    pastedimage1565939900249v3.png

    I tried the updated code in my instance and it worked well.

    function switchBPF(executioncontext) {
    var formContext = executioncontext.getFormContext();
    var statusreason = formContext.getAttribute("statuscode").getValue();
    var Application_type = formContext.getAttribute("dlg_applicationtype").getText();
    var activeProcessID = formContext.data.process.getActiveProcess().getId();
    if (statusreason != null) {
    if (Application_type == "Exemption Declaration" && activeProcessID.toUpperCase() != "76F74370-E600-44D3-A6F2-8716DC2D33B1")
    formContext.data.process.setActiveProcess("76F74370-E600-44D3-A6F2-8716DC2D33B1", callbackFunction);
    }
    }
    function callbackFunction(result) {
    if (result == "success") {
    alert("BPF successful")
    }
    else {
    alert("Failed");
    }
    }

    Hope it helps.

    Best Regards,

    Leo

  • TPY Profile Picture
    TPY 40 on at
    RE: How to Switch Business Process Flow automatically

    Hi Leo,

    Thank you for the link and the code. Appreciate if you could elaborate a little more on the code. With the help of your code, I have tried to do the below script, but failed to yield any result. If you could please have a look at it and help me.

    function switchBPF(executioncontext) {

    var formcontext = executioncontext.getFormContext();

    var statusreason = formContext.getAttribute("statuscode").getValue();

    var Application_type = formContext.getAttribute("dlg_applicationtype").gettext();

    var activeProcessID = formContext.data.process.getActiveProcess().getId();

    if (statuscode !=null){

    if (Application_type == "Exemption Declaration" && activeProcessID.toUpperCase()!= "%7b76F74370-E600-44D3-A6F2-8716DC2D33B1%7d")

    formContext.data.process.setActiveProcess("%7b76F74370-E600-44D3-A6F2-8716DC2D33B1%7d", callbackFunction);

    }

    };

    function callBackFunction(result)

    {

     if(result == “Success”)

     {

     alert("BPF successful")

     }

     else

     {

         alert ("Failed");

     }

    }

    Thanks heaps

    TPY.

  • TPY Profile Picture
    TPY 40 on at
    RE: How to Switch Business Process Flow automatically

    Hi Juneidi,

    Thank you for your response. I have gone through it and this still mentions the limitations on the number of entities and conditions we can specify in the design. (image below), unless its different in new UI.

    pastedimage1565934591281v1.png

    regards.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

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