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)

Set Date/Time Field to Date/Time Field in Related Entity using Javascript

(0) ShareShare
ReportReport
Posted on by

Using JavaScript, I need to retrieve a Date/Time value from a parent entity and set it to a Date/Time value on a child entity in the active form (based on another fields onchange event). I can retrieve the date but when I try to set the value of the field on screen it throws an error telling me "Value should be of type: DateTime". When I view the value in the parent field it looks like this: /Date(1548244800000)/ - essentially a formatted version of the value in milliseconds. Is there a conversion that will let me set this value into the child Date Time field?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi!

    You can use a function like this to set the value of your field:

    formContext.getAttribute("yourfield").setValue(formatDate (yourDate));

    function formatDate (date) {

           var dateObject = new Date(date);

           var isoDate = dateObject.toISOString();

           return "'" + isoDate.substring(0, 10) + "T00:00Z" + "'";

       },

    Hope it helps!

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Did you try new Date(<your returnedate>).

    stackoverflow.com/.../converting-milliseconds-to-a-date-jquery-javascript

    Hope this helps.

  • Community Member Profile Picture
    on at

    Thanks Luc,

    I didn't do it exactly that way but it did put me on the right track.

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