Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

JScript to Show/Hide Web resource on form

(0) ShareShare
ReportReport
Posted on by 175

Hi, I have a requirement for a simple JScript function.  I think I can piece together some of it as a non-developer, but am looking for the code regardless

Requirement: on Load/Save of form, or when field "dealreviewtype" = 'Green Folder Review', show web resource "publisher_webresourcename".  Else, on Load/Save of form, or when field "dealreviewtype" = 'LOI Review' or ' Contract Review', hide web resource "publisher_webresourcename". 

Any help is appreciated!

Thanks again.

pastedimage1573588471302v1.png

  • William Bradley Profile Picture
    175 on at
    RE: JScript to Show/Hide Web resource on form

    All - I was able to solve the issue with the below code and two event handlers OnLoad and OnChange:

    function ShowHideGreenFolderWR(context) {

    var formContext = context.getFormContext();

    var dealType = formContext.getAttribute("lennar_dealreviewtype").getValue();

    var wrGf = formContext.getControl("WebResource_GreenFolder");

    if(dealType == 2) {

    wrGf.setVisible(true);

    } else {

    wrGf.setVisible(false);

    }

    }

    Thanks so much to everybody for their assistance.

  • ajyendra Profile Picture
    1,732 on at
    RE: JScript to Show/Hide Web resource on form

    Did u check in your code that same number of opening and closing bracket in your code?

  • William Bradley Profile Picture
    175 on at
    RE: JScript to Show/Hide Web resource on form

    Sad to say, I updated to the code above on the web resource JScript, Saved, Published.  Still same error.

  • Suggested answer
    ajyendra Profile Picture
    1,732 on at
    RE: JScript to Show/Hide Web resource on form

    As I thought you miss the parameter in the function and also miss one closing bracket in your code. And

    function ShowHideGreenFolderWR(executionContext)

    {

    var formContext = executionContext.getFormContext();

    var dealType = formContext.getControl("lennar_dealreviewtype").getValue();

    if (dealType == 2) {

    Xrm.Page.getControl("WebResource_GreenFolderReview").setVisible(true);

    } else {

    Xrm.Page.getControl("WebResource_GreenFolderReview").setVisible(false);

    }

    }

  • William Bradley Profile Picture
    175 on at
    RE: JScript to Show/Hide Web resource on form

    Ajyendra - sure - here are screenshots/examples for what you have asked for how the issue stands currently.  

    Web Resource:


    pastedimage1573744249631v1.png

    Web Resource JavaScript:

    pastedimage1573744266665v2.png

    Web Resource Properties - Deal Review Entity Form:

    pastedimage1573744390713v3.png

    Form Properties - Library and Events:

    pastedimage1573744450800v4.png

    Handler Properties:

    pastedimage1573744504525v5.png

    Screenshot of Error - when selecting any value in the Deal Review Type (******_dealreviewtype) option set (Null, LOI Review (0), Contract Review (1), Green Folder (2)

    When Green Folder (2) is selected, the GreenFolderReviewWR web resource is supposed to show below the Deal Review Type.

    pastedimage1573744739102v6.png

    I have tried debugging the code, the function seems correct.  The error "Web resource method doesn't exist" seems to indicate the method does not exist in the file its being called from.

    Thoughts?

  • ajyendra Profile Picture
    1,732 on at
    RE: JScript to Show/Hide Web resource on form

    Can you share code with us this time proper code what you use exact check with curly bracket(right now you are using) ? Also share screenshot with us same as I posted previous reply . Can you try with new webresource? Also debug your code in console Press F12 from keyboard in Chrome browser then Press Ctrl + P and enter name of  the webresource file where you have your function then Check that webresource file contain your function  or not in console.

  • William Bradley Profile Picture
    175 on at
    RE: JScript to Show/Hide Web resource on form

    Thanks Aiyendra - yes I saved and published web resource.  Added to form library and Event and saved and published each time I update.  Still same error.

  • ajyendra Profile Picture
    1,732 on at
    RE: JScript to Show/Hide Web resource on form

    Sorry for asking but Did you properly save and publish that form /web resource file where that function is located?

    if Yes try to create new webresource js file and put only this function in it . Make sure it every bracket open and close. For simplicity I put your code below just copy from here and paste

    function ShowHideGreenFolderWR(context) {

      var formContext = context.getFormContext();

          var dealType = formContext.getControl("lennar_dealreviewtype").getValue();

          if (dealType == 2)

          {

              Xrm.Page.getControl("WebResource_GreenFolderReview") ? Xrm.Page.getControl("WebResource_GreenFolderReview").setVisible(true) : false;

          } else {

              Xrm.Page.getControl("WebResource_GreenFolderReview") ? Xrm.Page.getControl("WebResource_GreenFolderReview").setVisible(false) : false;

          }

    }

    Copy and paste from here as it is .

    Note: make sure Save and Publish webresource properly. Also Publish the form if you do with Form Editor(no need but just for precaution)

  • William Bradley Profile Picture
    175 on at
    RE: JScript to Show/Hide Web resource on form

    Thanks - I believe everything is correct in the below Script, so the function should be working.  Not sure why it is not.

    function ShowHideGreenFolderWR()

    {

    var dealType = formContext.getControl("lennar_dealreviewtype").getValue();

    if (dealType == 2) {

    formContext.getControl("lennar_greenfoldereview").setVisible(true);

    } else {

    formContext.getControl("lennar_greenfolderreview").setVisible(false);

    }

  • gdas Profile Picture
    50,089 Moderator on at
    RE: JScript to Show/Hide Web resource on form

    Download visual studio and write your code there to avoid this kind of bracket issue ()).

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,120 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,871 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans