Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

catching error on JS

Posted on by 790

dear all

i am retrieving the value of (Xrm.Page.getAttribute('subjectid').getValue()[0].name) on case entity at the FORM LOAD event to be able to show/hide certain fields, but apparently, if i select to create new case, then the value of the above variable is null and catching the error does not help, it always through an error.

can you help me.,

thanks,

*This post is locked for comments

  • Ahmad Saud Profile Picture
    Ahmad Saud 790 on at
    RE: catching error on JS

    thanks, it works now.

    regards.

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: catching error on JS

    Hi Ahmad ,

    Please put null check  before you are executing "Xrm.Page.getAttribute('subjectid').getValue()[0].name"  line as  "Xrm.Page.getAttribute('subjectid').getValue() " getting null and thats why unable to get "[0].name" value.

     if (Xrm.Page.getAttribute('subjectid').getValue() != null && Xrm.Page.getAttribute('subjectid').getValue() != undefined) {

      // get the value

    var  str = Xrm.Page.getAttribute('subjectid').getValue()[0].name ;

    }

    If this is not helps you , share your code , I will correct .

  • Ahmad Saud Profile Picture
    Ahmad Saud 790 on at
    RE: catching error on JS

    thanks Goutam, still the same problem , please check the following :

    2018_2D00_07_2D00_29-12_5F00_04_5F00_28_2D00_Case_5F00_-New-Case.jpg

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: catching error on JS

    Hi Ahmad,

    Apart from null check you can also check "form type" and based on that implement show hide logic.

    Here is sample code -

    function ShowHideField() {
    
        if (Xrm.Page.ui.getFormType() == 2) // For Upadte
        {
    
            if (Xrm.Page.getAttribute('subjectid').getValue() != null && Xrm.Page.getAttribute('subjectid').getValue() != undefined) {
                // Do the show hide here in case of Update
    
    
            }
        }
        else if (Xrm.Page.ui.getFormType() == 1) {  // For Create
    
       
        }
    
    }


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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans