Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Hiding and showing BPF

(0) ShareShare
ReportReport
Posted on by 4
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                                          
    }
}
 
  • Suggested answer
    Nitesh Raj Profile Picture
    Nitesh Raj 14 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

Congratulations 2024 Spotlight Stars!

Kudos to all of our 2024 community stars!

Meet the Top 10 leaders for December!

Congratulations to our December super stars!

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,596 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans