Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Hiding and showing BPF

(0) ShareShare
ReportReport
Posted on by 9
HI
 
I am trying to use JS to show or hide the BPF on a table based on a value from a choice field. I am not a Dev or able to write JS myself so have been searching for different options. I have tried the following which i found but i get an error (executionContext is not defined). I have also tried other scripts but had no luck. Is the code below valid and/or what dod i need to do to get it working or is there a better way
 
Thanks
 
function HideOrShowBPF() {
    var formContext = executionContext.getFormContext();
    var AgreementType = formContext.getAttribute("uow_internationalagreementtype").getValue();
    if (AgreementType  == "942210001") {
       Xrm.Page.ui.process.setVisible(true); //Show Business Process Flow   
    }
    else  {
       Xrm.Page.ui.process.setVisible(false);  //Hide Business Process Flow                                          
    }
}
 
  • WaikatoUni Profile Picture
    WaikatoUni 9 on at
    Hiding and showing BPF
    Thanks Nitesh. I added to the on-load rather than on-save as that way it shows when i open
     
    Regards
    Nigel
  • CU06011034-0 Profile Picture
    CU06011034-0 4 on at
    Hiding and showing BPF
    Hello,

    Please refer to below link :

    https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/formcontext-data-process

    This way it should work

    Hide:-  Xrm.Page.ui.process.setVisible(false);

    Show:-  Xrm.Page.ui.process.setVisible(true);

    Hope you have called your JS library file with right method in form OnSave OnLoad and even in field OnChange 

     
  • Suggested answer
    Nitesh Raj Profile Picture
    Nitesh Raj 74 on at
    Hiding and showing BPF
    You have to do 2 things, for your script to work.

    1) Pass execution context from the form: (see the below image for reference) 
    - In event handler, click on the checkbox in front of "Pass execution context as first parameter" 
    - As you can see i have selected "Finished ? " field first, then selected onChange -> Event Handler. Add the web resource which you have saved. Paste the function name, in your case it is "HideOrShowBPF". select both options (Enabled and pass execution context as first parameter). Click Done. Click "Save and Publish". 

    2) In your script (script = web resource = javascript), you have to add the execution context in the function call and also while comparing (in the if statement), compare with number value (without "" and with three =).

    Just copy below script: 

    Updated Script:

    ----
     
    function HideOrShowBPF(executionContext) {
        var formContext = executionContext.getFormContext();
        var AgreementType = formContext.getAttribute("uow_internationalagreementtype").getValue();
        if (AgreementType  === 942210001) {
           Xrm.Page.ui.process.setVisible(true); //Show Business Process Flow   
        }
        else  {
           Xrm.Page.ui.process.setVisible(false);  //Hide Business Process Flow                                          
        }
    }

    ----

    Double check the 942210001 number in your option set, is it correct. 

    And this script only will run when you change the dropdown value. Means, If you have selected let's say option hide (value: 942210001) then it will hide the bpf in the form. but when you re-visit (close and reopen the form) the bpf will be there. 

    To hide the bpf when you open the form you have to add this same script in the on save event handler in the form's event.

    If you find this answer any helpful, please, approve it. 

    Thanks,
    Nitesh



     

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,468 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,287 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans