Skip to main content

Notifications

Service | Customer Service, Contact Center, Fie...
Suggested answer

Switching BPFs in same entity

Posted on by 153

I have created two BPFs in the same entity and I want to switch BPF according to my selection in a choice field in the form.

6278.choice.jpg

I am also defining the event handler as on save option.

And my js code which I am using

function onLoadChangeBPFByType(executionContext) {
var formContext = executionContext.getFormContext();
var oppType = formContext.getAttribute(“casetypecode”).getText();
var activeProcessID = formContext.data.process.getActiveProcess().getId();
if (oppType == “Wildfire Case” && activeProcessID.toUpperCase() != “0ffbcde4-61c1-4355-aa89-aa1d7b2b8792”) formContext.data.process.setActiveProcess(“0ffbcde4-61c1-4355-aa89-aa1d7b2b8792”, callBackFunction);
};
function callBackFunction(result) {
if (result == “success”) {} else {}
}

And the error which I am getting is

ReferenceError: Web resource method does not exist: onLoadChangeBPFByType

Error Details:
Event Name: onsave
Function Name: onLoadChangeBPFByType
Web Resource Name: cr7af_SwitchBPF.js
Solution Name: Active
Publisher Name: DefaultPublisherorg6de6fc86

  • Prashant.ITT Profile Picture
    Prashant.ITT 153 on at
    RE: Switching BPFs in same entity

    function onLoadChangeBPF() {

    var oppType = Xrm.Page.data.process.getAttribute("casetypecode").getText();

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

    if (activeProcess != null){

       if (oppType == "Wildfire Case" && activeProcessID.toUpperCase() != "0ffbcde4-61c1-4355-aa89-aa1d7b2b8792"){

           Xrm.Page.data.process.setActiveProcess("0ffbcde4-61c1-4355-aa89-aa1d7b2b8792", callBackFunction);

       }

    }

    function callBackFunction(result) {

    if (result == "success") {} else {}

    }

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Switching BPFs in same entity

    Hi,

    Can you share entire code from SwitchBPF.js?

    Are you using any namespace in your code?

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Suggested answer
    Nya Profile Picture
    Nya 29,056 on at
    RE: Switching BPFs in same entity

    Hi,

    As you need to switch the BPF when you changed the value of the case type, it is recommended to set the event as an OnChange event.

    Column OnChange Event in model-driven apps - Power Apps | Microsoft Docs

    pastedimage1646905543860v2.png

    And the Process Id gotten in your code snippet could be null if there is no active process in the form.

    var activeProcess = Xrm.Page.data.process.getActiveProcess();
    if (activeProcess != null){
        if (oppType == "Wildfire Case" && activeProcessID.toUpperCase() != "0ffbcde4-61c1-4355-aa89-aa1d7b2b8792"){ 
            formContext.data.process.setActiveProcess("0ffbcde4-61c1-4355-aa89-aa1d7b2b8792", callBackFunction);
        }
    }

  • Prashant.ITT Profile Picture
    Prashant.ITT 153 on at
    RE: Switching BPFs in same entity

    Form-Properties.jpg

  • Nya Profile Picture
    Nya 29,056 on at
    RE: Switching BPFs in same entity

    Hi Prashant Kumar,

    According to the error message, it seems that the function does not correspond to the JS web resource.

    Would you please share the screenshot of the form libraries and Event Handlers in the Form properties?

    Is it set as an OnLoad event or an OnSave event? Why the event name are different in both of the error messages you provided?

  • Prashant.ITT Profile Picture
    Prashant.ITT 153 on at
    RE: Switching BPFs in same entity

    Still getting same error:

    Web resource method does not exist: onLoadChangeBPFByType

    Session Id: 85cc93e4-63d0-42ff-b3dd-f47d933cd054

    Correlation Id: 0083fe83-3f17-4176-aea3-6a86b4523614

    Event Name: onload

    Function Name: onLoadChangeBPFByType

    Web Resource Name: cr7af_SwitchBPF.js

    Solution Name: Active

    Publisher Name: DefaultPublisherorg6de6fc86

    Time: Wed Mar 09 2022 17:25:45 GMT+0530 (India Standard Time)

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Switching BPFs in same entity

    HI,

    Please check if you have any syntax error in your JS code. Please copy all code from cr7af_SwitchBPF.js and check the syntax using below online tool.

    esprima.org/.../validate.html

    I have updated your code to use correct double quotes ("")

    function onLoadChangeBPFByType(executionContext) {

    var formContext = executionContext.getFormContext();

    var oppType = formContext.getAttribute("casetypecode").getText();

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

    if (oppType == "Wildfire Case" && activeProcessID.toUpperCase() != "0ffbcde4-61c1-4355-aa89-aa1d7b2b8792") formContext.data.process.setActiveProcess("0ffbcde4-61c1-4355-aa89-aa1d7b2b8792", callBackFunction);

    };

    function callBackFunction(result) {

    if (result == "success") {} else {}

    }

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

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 Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

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... 290,912 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,355 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans