web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

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 17
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                                          
    }
}
 
I have the same question (0)
  • Suggested answer
    Nitesh Raj Profile Picture
    188 on at
    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



     
  • CU06011034-0 Profile Picture
    4 on at
    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 

     
  • WaikatoUni Profile Picture
    17 on at
    Thanks Nitesh. I added to the on-load rather than on-save as that way it shows when i open
     
    Regards
    Nigel

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 77 Super User 2025 Season 2

#3
TAHER Mehdi Profile Picture

TAHER Mehdi 46

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans