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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Java Script help to hide show web resource

(0) ShareShare
ReportReport
Posted on by 92

Could someone help me with sample JavaScript to hide or show webresource based on entity create date after 12/1/20222.

So logic I am looking to impliment,

If Create Date is before 12/1/22

    Show WebResource_A 

    Hide WebResource_B

else

   Hide WebResource_A 

   Show WebResource_B

I have the same question (0)
  • Matthew Nguyen Profile Picture
    10 on at

    Hi VANTAGE,

    I just have a suggestion that is it not more suitable to put your code within the condition of the creation date?

  • Suggested answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi VANTAGE,

    Add these Web resources in a different section or tab. Hide these sections/tabs on the basis of your condition with your appropriate user interface triggers.

    For more details: learn.microsoft.com/.../setvisible

  • Suggested answer
    Tamilarasu Arunachalam Profile Picture
    587 on at

    As per my understanding to your question, I want to know your web resource is an image(png or jpeg) file or html file or JavaScript file.

    If it is an image file or html, you could write a condition to hide and show, but i don't know if there are options to hide JavaScript  file

    If you found it useful, like or verify my answer

  • VANTAGE Profile Picture
    92 on at

    It's an html web resource. I don't know JavaScript so I am just trying to figure it out. Does my code look correct?

    I am trying to code if createdon date is less than 12/1/22 then show old section otherwise if createdon is blank or greater than 12/1/22 then show new section.

    function showHideSection(executionContext)
    {
    var formContext = executionContext.getFormContext();

    var createdOn = formContext.getAttribute("createdon").getValue();

    var OldRateDate = new Date("2022-12-01);


    if createdOn != null && createdOn < OldRateDate
    {
    formContext.ui.tabs.get("{my tab value goes here}").sections.get("reimbursement_rate_125").setVisible(true);
    formContext.ui.tabs.get("{my tab value goes here}").sections.get("reimbursement_clause_old").setVisible(false);
    }
    else
    {
    formContext.ui.tabs.get("{my tab value goes here}").sections.get("reimbursement_rate_125").setVisible(false);
    formContext.ui.tabs.get("{my tab value goes here}").sections.get("reimbursement_clause_old").setVisible(true);
    }
    }

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Your code looks good but comparison line. It should look like this:

    if (createdOn != null && createdOn < OldRateDate)

  • VANTAGE Profile Picture
    92 on at

    I am getting the following error on form load. I have published form and double-checked Form properties to make sure function file is uploaded and spelling is correct when calling function.

    Web resource method does not exist: showHideSection

    Session Id: 0980a1cf-ccfb-4af1-a81c-8644cf020404

    Correlation Id: 9c985a11-59fb-4dd5-a36d-1729834ccdc4

    Event Name: onload

    Function Name: showHideSection

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Can you please provide your full code? Not the function itself but all of it.

  • VANTAGE Profile Picture
    92 on at

    function showHideSection(executionContext)
    {
    var formContext = executionContext.getFormContext();

    var createdOn = formContext.getAttribute("createdon").getValue();

    var OldRateDate = new Date("2022-12-01);


    if (createdOn != null && createdOn < OldRateDate)
    {
    formContext.ui.tabs.get("{226d192b-e5b7-45f4-886a-76f1fd1a2ec2}").sections.get("reimbursement_rate_125").setVisible(true);
    formContext.ui.tabs.get("{226d192b-e5b7-45f4-886a-76f1fd1a2ec2}").sections.get("reimbursement_clause_old").setVisible(false);
    }
    else
    {
    formContext.ui.tabs.get("{226d192b-e5b7-45f4-886a-76f1fd1a2ec2}").sections.get("reimbursement_rate_125").setVisible(false);
    formContext.ui.tabs.get("{226d192b-e5b7-45f4-886a-76f1fd1a2ec2}").sections.get("reimbursement_clause_old").setVisible(true);
    }
    }

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    You missed the closing quote here:

    var OldRateDate = new Date("2022-12-01");

    You can use the following website to validate if your JavaScript is valid - beautifytools.com/javascript-validator.php

  • VANTAGE Profile Picture
    92 on at

    I finally got it working with further logic tweaking. Thank you so much to everyone.

    function showHideSection(executionContext)

    {

    var formContext = executionContext.getFormContext();

    var createdOn = formContext.getAttribute("createdon").getValue();

    var OldRateDate = new Date("2022-12-01");

    if (createdOn == null || createdOn > OldRateDate)

    {

    formContext.ui.tabs.get("{226d192b-e5b7-45f4-886a-76f1fd1a2ec2}").sections.get("reimbursement_rate_125").setVisible(true);

    formContext.ui.tabs.get("{226d192b-e5b7-45f4-886a-76f1fd1a2ec2}").sections.get("reimbursement_clause_old").setVisible(false);

    }

    else

    {

    formContext.ui.tabs.get("{226d192b-e5b7-45f4-886a-76f1fd1a2ec2}").sections.get("reimbursement_rate_125").setVisible(false);

    formContext.ui.tabs.get("{226d192b-e5b7-45f4-886a-76f1fd1a2ec2}").sections.get("reimbursement_clause_old").setVisible(true);

    }

    }

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

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
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans