Skip to main content

Notifications

Announcements

No record found.

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

JScript error on show/hide of Web Resource HTML

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. 


  • William Bradley Profile Picture
    William Bradley 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
    ajyendra 1,730 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
    Joana Pinto 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
    William Bradley 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
    ajyendra 1,730 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans