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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM and JavaScript error when trying to see if date field contains data

(0) ShareShare
ReportReport
Posted on by 26

I have the following script, but when I select a date in the SlideDeckDueDate Field I get and error that says, "Object doesn't support property or method 'getText' at SlideDeckDueDateOnChange."  I just want to check to see if this field contains data, and if so, then make other fields required. What am I doing wrong?

function SlideDeckDueDateOnChange()
 {
 var SlideDeckDueDate = Xrm.Page.getAttribute("nhs_slidedeckduedate").getText();
 
  if (SlideDeckDueDate == null || SlideDeckDueDate =='undefined' || SlideDeckDueDate =='')
   {
    Xrm.Page.getAttribute("nhs_currenttimeframe").setRequiredLevel("none");
    Xrm.Page.getAttribute("nhs_previoustimeframe").setRequiredLevel("none");
   }
  else if (SlideDeckDueDate != null && SlideDeckDueDate != 'undefined' && SlideDeckDueDate !='')
   {
    Xrm.Page.getAttribute("nhs_currenttimeframe").setRequiredLevel("required");
    Xrm.Page.getAttribute("nhs_previoustimeframe").setRequiredLevel("required");
   }
 }

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi There,

    I think it is due the fact that "getText()" only supports and used for optionset and multioptionset fields. hence you get that error.

    if you just need to check if date time field has data , you can do something like below using getValue().

    var SlideDeckDueDate = Xrm.Page.getAttribute("nhs_slidedeckduedate").getValue();

    then check if (SlideDeckDueDate  != null)

    {

    }

    However i have strong feeling that whatever you doing on the script above can very well be accomplished using a simple business rule?

  • USA80 Profile Picture
    26 on at

    That worked, thank you.  I could have done this in a business rule, but I have other logic in a script already and wanted to stay consistent instead of having some logic in a script and some in a business rule.  Thank you for your help.  

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans