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

Community site session details

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

JScript error on show/hide of Web Resource HTML

(0) ShareShare
ReportReport
Posted on by 175

Hi all, 

I am receiving an error when implementing a few J Script functions on a form.  The purpose of this script is to show/hide a basic HTML web resource based on a flag.  I have another web resource working on the form that looks like this:

pastedimage1572433108220v1.png

The above is using this function:


function visibilityOfPublishWR (executionContext) {
var formContext = executionContext.getFormContext();
var lmsdoc = formContext.getAttribute("lennar_lmsdocument").getValue();
var isfileattached = formContext.getAttribute("lennar_isfileattached").getValue();
if (lmsdoc != null && isfileattached == null)
{
formContext.getControl("WebResource_PublishRecordLockedHTMLFA").setVisible(true);
}
else {
formContext.getControl("WebResource_PublishRecordLockedHTMLFA").setVisible(false);
}
}

I have another web resource similiar to the above that I want to show/hide onLoad based on this function (basically, it prompts the user to Review the form/document before truly publishing the record):

function visibilityOfPubReviewWR (executionContext)
{
var formContext = executionContext.getFormContext();
var isFileAttached = formContext.getAttribute("lennar_isfileattachedos").getValue();
if (isFileAttached === null)
{
formContext.getControl("WebResource_PublishRecordReviewLockHTMLFA").setVisible(false);
}
else
{
formContext.getControl("WebResource_PublishRecordReviewLockHTMLFA").setVisible(true);
}
}

This above is not working.  I get the below error onLoad of the page:


TypeError: Cannot read property 'getValue' of null
at visibilityOfPublishWR (lennardev.crm.dynamics.com/.../lennar_VisibilityofPublishWebResource:4:71)
at Cp.executeFunction (lennardev.crm.dynamics.com/.../app.js
at Cp.execute (lennardev.crm.dynamics.com/.../app.js
at fp._executeIndividualEvent (lennardev.crm.dynamics.com/.../app.js
at fp._executeEventHandler (lennardev.crm.dynamics.com/.../app.js
at Object.execute (lennardev.crm.dynamics.com/.../app.js
at C._executeSyncAction (lennardev.crm.dynamics.com/.../app.js
at C._executeSync (lennardev.crm.dynamics.com/.../app.js
at C.executeAction (lennardev.crm.dynamics.com/.../app.js
at t.dispatch (https://lennardev.crm.dynamics.com/uclient/scripts/app.js?v=1.3.2371-191024-232557:476:5545)

I thought it was syntax, but changed a few things related to the isFileAttached === null) - but to no avail.

Can someone help troubleshoot this code?

Thanks so much in advance. 


I have the same question (0)
  • William Bradley Profile Picture
    175 on at
    RE: JScript error on show/hide of Web Resource HTML

    All fixed!  Thanks for your help, all.  

  • Suggested answer
    ajyendra Profile Picture
    1,738 on at
    RE: JScript error on show/hide of Web Resource HTML

    One more thing I need to mention the function visibilityOfPublishWR

    The line formContext.getAttribute("lennar_isfileattached").getValue() that field is lennar_isfileattached or lennar_isfileattachedos?

    Is both field is different

  • Joana Pinto Profile Picture
    740 on at
    RE: JScript error on show/hide of Web Resource HTML

    Hi,

    When does your script get loaded, on what trigger event?

  • William Bradley Profile Picture
    175 on at
    RE: JScript error on show/hide of Web Resource HTML

    Thanks for the reply.  That field, "IsFileAttached", has a schema name of "lennar_isfileattachedos" ...

  • Suggested answer
    ajyendra Profile Picture
    1,738 on at
    RE: JScript error on show/hide of Web Resource HTML

    Hi,

    Seems Code is all right.

    It might be because of wrong field name .Please Cross verify the field name lennar_isfileattachedos

    formContext.getAttribute("lennar_isfileattachedos").getValue()

    Hope it works

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daniyal Khaleel Profile Picture

Daniyal Khaleel 143

#2
DAnny3211 Profile Picture

DAnny3211 134

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans