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)

How to get the value of the date field...

(0) ShareShare
ReportReport
Posted on by 26

I have a date field called "Data Requested."  I need to grab the date from this field and put it in the name of the record when it is saved.  Currently when I hit save it is grabbing the data and time, and what time zone.  The Date Requested field is showing correctly when the user picks a date, for instance it shows 2/21/2019.  So I need to somehow get the date of 2/21/2019 to show up, not the date, hour, time zone.  I can't use a business rule because I am concatenating other fields for the name of the record.

Any help is appreciated.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Try with this -

                function SetNameWithDate() {
                    var dateTimeValue = Xrm.Page.getAttribute("new_datefiledNaem").getValue()  // Replace the date filed Name
                    var crmDateValue = new Date(dateTimeValue);
                    var reqdateValue = (crmDateValue.getMonth() + 1)  + '/' +crmDateValue.getDate() + '/' + crmDateValue.getFullYear();               
                    Xrm.Page.getAttribute("new_namefieldname").setValue(reqdateValue); // Replace the date filed Name
                }
  • USA80 Profile Picture
    26 on at

    So that worked, however I have another question.  So currently I am concatenating a bunch of fields to make the name of the record.  For instance I now have the name showing, "Ongoing_Hi_2/25/2019_Adherence, Outcome"

    but the Adherence and Outcome fields are currently checkboxes and if the answer is No, then I don't want their name showing up.  For Example, the user says No to Outcome....I want to see the name to be "Ongoing_Hi_2/25/2019_Adherece", but  I am currently seeing "Ongoing_Hi_2/25/2019_Adherece, null"

  • USA80 Profile Picture
    26 on at

    Here is my current script:

    function onSaveSetName ()

    {

      var separator =  " _ " ;

      var comma = " , " ;

      var frequency = Xrm.Page.getAttribute("nhs_frequency").getValue();

      var datarequested = Xrm.Page.getAttribute("nhs_datarequested").getValue();

      var orgid = Xrm.Page.getAttribute("nhs_orgid").getValue();

      var carrierid = Xrm.Page.getAttribute("nhs_carrierid").getValue();

      var adherence = Xrm.Page.getAttribute("nhs_adherencetext").getValue();

      var outcome = Xrm.Page.getAttribute("nhs_outcometext").getValue();

      if (frequency !=null && orgid !=null && datarequested !=null)

    {

    var frequencyText = Xrm.Page.getAttribute("nhs_frequency").getText();

    var crmDateValue = new Date(datarequested);

           var reqdateValue = (crmDateValue.getMonth() + 1)  + '/' +crmDateValue.getDate() + '/' + crmDateValue.getFullYear();              

    var new_setname = frequencyText + separator + orgid + separator + reqdateValue + separator + adherence + comma + outcome;

    Xrm.Page.getAttribute("nhs_projectname").setValue(new_setname);

    }

    else if (frequency ==null || orgid ==null || datarequested ==null)

    {

    Xrm.Page.getAttribute("nhs_projectname").setValue();

    }

    }

  • gdas Profile Picture
    50,091 Moderator on at

    Do you have any other checkbox fields?  what is the field type of  nhs_adherencetext, nhs_outcometext  ?

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

    Assuming that you have a check box field , so you can try below -

                function onSaveSetName ()
                {
                    var separator =  " _ " ;
                    var comma = " , " ;
                    var frequency = Xrm.Page.getAttribute("nhs_frequency").getValue();
                    var datarequested = Xrm.Page.getAttribute("nhs_datarequested").getValue();
                    var orgid = Xrm.Page.getAttribute("nhs_orgid").getValue();
                    var carrierid = Xrm.Page.getAttribute("nhs_carrierid").getValue();
                    var adherence = Xrm.Page.getAttribute("nhs_adherencetext").getValue();
                    var outcome = Xrm.Page.getAttribute("nhs_outcometext").getValue();
                    var adherencecheck =Xrm.Page.getAttribute("nhs_outcomeCheckBox").getValue();
                    var outcomecheck =Xrm.Page.getAttribute("nhs_adherenceCheckBOx").getValue();
                    if (frequency !=null && orgid !=null && datarequested !=null)
                    {
                        var frequencyText = Xrm.Page.getAttribute("nhs_frequency").getText();
                        var crmDateValue = new Date(datarequested);
                        var reqdateValue = (crmDateValue.getMonth() + 1)  + '/' +crmDateValue.getDate() + '/' + crmDateValue.getFullYear();
                        var new_setname = frequencyText + separator + orgid + separator + reqdateValue;
                        if(adherencecheck == true && adherence !=null && adherence !=undefined)                    
                        {
                            new_setname = new_setname + separator + adherence;
                        }
                        if (outcomecheck == true && outcome != null && outcome !=undefined)
                        {
                            new_setname = new_setname + comma + outcome;
                        }
                        Xrm.Page.getAttribute("nhs_projectname").setValue(new_setname);
                    }
                    else if (frequency ==null || orgid ==null || datarequested ==null)
                    {
                        Xrm.Page.getAttribute("nhs_projectname").setValue();
                    }
                }


  • USA80 Profile Picture
    26 on at

    I do have other checkbox fields.  Below is all of my checkboxes.  The fields that you see "Text" behind them.  I am using those fields that if the checkbox field above them are Yes, then the text field would show the label in that field.  So then I could use that field to grab and put in the record name.  Not sure if there is an easier way to do this?

    I need to be able to check all the text fields and then grab the text fields that only contain data in them and bring them into the naming convention of the record.

    2577.checkbox.png

  • gdas Profile Picture
    50,091 Moderator on at

    ok try with my code which I shared .

  • USA80 Profile Picture
    26 on at

    Your script worked for the 2 checkboxes.  Now how do I do the others?  Do I have to write out every possible scenario or is there an easier way?

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

    yes you have to write similar way.

  • USA80 Profile Picture
    26 on at

    That's a lot of different scenarios.  Darn.

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