Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Event on Switch BPF through Switch process button

Posted on by 15

I have multiple BPF's for a entity. I have events registered onStageChange  & onStageSelected of the BPF. These function are written on the onload block of the JS. 

I can switch the BPF using the Switch Process ribbon button. When I switch the process then the onload block executes and sets the field value of a custom field but it is not saved . It gets reflected as unsaved changes. There is a custom function which sets the value of that custom field but it doesn't save the value.  The value is only saved only after explicitly saving the form. 

If I would explicitly save the form in the custom function it would again call the function which is registered on onSave event. 

Any suggestions /approaches to overcome the issue of unsaved changes on BPF switch.

Thanks in advance!

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Event on Switch BPF through Switch process button

    Hi Shrivesh Tatte,

    Please try these ways:

    1. Still save the form in the custom  function but you need to pass the saveOptions parameter in which you need to customize a save mode number(Please don't use the number in this list) to the formContext.data.save() function. Something like this:

    //customize a SaveMode number
    formContext.data.save({"saveMode":71});

    Then in your onSave event, please add these lines to make your business not executed:

    function onSave(executionContext){
        var saveMode = executionContext.getEventArgs().getSaveMode();
        if(saveMode == 71){
             return;
        }
        //your business
        ...
    }

    This way would still trigger the onSave event.

    2. Don't use formContext.data.save() in your custom function. Instead, use Web API to update your current record and invoke the formContext.data.refresh(false) function in the success callback function to refresh the data. This way wouldn't trigger the onSave event.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans