Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

Javascript on load question

(0) ShareShare
ReportReport
Posted on by 70

I have a script that is popping a message on load. If the field i'm checking has a value it works as it should but if the field is null i get an error. What can i add to the script to fix that error? 

function checkAccountingStatus() {
 var accountingstatus = Xrm.Page.getAttribute('accountratingcode').getSelectedOption();
  if (accountingstatus.value == 282740001) {
   Xrm.Utility.alertDialog("The Account is in Collections.");
 }
}
  • Verified answer
    Dynamics365 Rocker Profile Picture
    7,755 on at
    RE: Javascript on load question

    Use getValue() in place of get selected option.

  • Chris Holst Profile Picture
    70 on at
    RE: Javascript on load question

    Still getting an error when accounting status is null. Here is the error and the updated code. 

    TypeError: Cannot read property 'value' of null at checkAccountingStatus (devarinet.crm.dynamics.com/.../ari_CollectionsPopup)

    function checkAccountingStatus() {
       var accountingstatus = Xrm.Page.getAttribute('accountratingcode');
       if (accountingstatus != null) {
       		var accountingstatusValue = Xrm.Page.getAttribute('accountratingcode').getSelectedOption();
       		if (accountingstatusValue.value == 282740001) {
          		Xrm.Utility.alertDialog("The Account is in Collections.");
    		}
    	}
    }
  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at
    RE: Javascript on load question

    Update code as below:

    function checkAccountingStatus() {

    var accountingstatus = Xrm.Page.getAttribute('accountratingcode');

    if(accountingstatus!=null)

    {

    var accountingstatusValue = Xrm.Page.getAttribute('accountratingcode').getSelectedOption();

     if (accountingstatus.Valuevalue == 282740001) {

      Xrm.Utility.alertDialog("The Account is in Collections.");

    }

    }

    }

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Dynamics 365 general forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans