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)

Show yes or No based on date value

(0) ShareShare
ReportReport
Posted on by 815

Hi,

Can anyone help if this possible to do.

There are three fields, two date fields name as Start date and end date and one text field.

User will manually fill start and end date

Condition is : 

If end date is less then 365 days from current date then it show as YES on text field

If end date is greater then 365 days from current date then it show as No on text field

For easy understanding this for warranty calculation.

Please help.

Regards

Faisal

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at

    Yes you can do it by Script or business rule.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Sayed ,

    Try with this  -

        function SetTxtField() {
            var crmstartDate = Xrm.Page.getAttribute("new_startDate").getValue();
            var crmendDate = Xrm.Page.getAttribute("new_endDate").getValue();
    
            var startdate = new Date(crmstartDate);
            var enddate = new Date(crmendDate);
    
            var timeDiff = Math.abs(enddate.getTime() - startdate.getTime());
            var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
            if (diffDays < 365) {
                Xrm.Page.getAttribute("new_textfield").setValue("Yes");
            }
            else {
                Xrm.Page.getAttribute("new_textfield").setValue("No");
            }
        }


  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Please do null check of date field which i forgot and register the function in on change event of date.

  • Syed_Faisal Profile Picture
    815 on at

    Hi Gowtham,

    Getting this below error.

    TypeError: Cannot read property 'setValue' of null

  • Dynamics365 Rocker Profile Picture
    7,755 on at

    what is name of your field?

  • Syed_Faisal Profile Picture
    815 on at

    text field name = new_warrantystatus

  • Dynamics365 Rocker Profile Picture
    7,755 on at

    Xrm.Page.getAttribute("new_warrantystatus").setValue("Yes");

           }

           else {

               Xrm.Page.getAttribute("new_warrantystatus").setValue("No");

    and make sure that this field should be on form.

  • Syed_Faisal Profile Picture
    815 on at

    I already have added the same code which is mentioned by gowtam but he told to do the null check on the date field.

  • gdas Profile Picture
    50,091 Moderator on at

    Please share your complete code .

  • Syed_Faisal Profile Picture
    815 on at

    function SetTxtField() {

           var crmstartDate = Xrm.Page.getAttribute("new_manufacturedate").getValue();

           var crmendDate = Xrm.Page.getAttribute("new_warrantyenddate1").getValue();

           var startdate = new Date(crmstartDate);

           var enddate = new Date(crmendDate);

           var timeDiff = Math.abs(enddate.getTime() - startdate.getTime());

           var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

           if (diffDays < 365) {

               Xrm.Page.getAttribute("new_warrantystatus").setValue("Yes");

           }

           else {

               Xrm.Page.getAttribute("new_warrantystatus").setValue("No");

           }

       }

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