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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans