Convert date to date/time value

Leonel Sandroni
Tera Guru

Hi there!

I'm trying to accomplish with a client requirement. They need to move the date of due date field in demands to the due date field in enhancement. Field specifications are as follows:

 

Due Date Demands:

  • table: dmn_demand 
  • type: date

Due Date in enhancements:

  • table: task
  • type: date/time

In order to move this value from demand to enhancement I have modified the script that create enhancements from demands with this statement:

LeonelSandroni_0-1737469732086.png

It seems to work correctly but there is a little problem that you can check below:

Demand:

LeonelSandroni_1-1737469962955.png

Enhancements

LeonelSandroni_2-1737470283976.png

 

You can see how enhancemetns takes the previous day at 17:00 to the one I put in demands

 

Is there anyway to adjust this in order to get the same dates in both fields?

thanks!!!

 

 

 

1 ACCEPTED SOLUTION

@Leonel Sandroni 

I already informed in my 1st response it's because of the mismatch in field type

2 ways

1) create a new date field and set the value

OR

2) let the date value be populated in date/time with 00:00:00 in GMT and discuss with your customer

I won't recommend updating the OOB field on enhancement table.

Hiding of time in due date is not recommended and would be possible with client script.

Even if it's feasible it would require DOM manipulation which is not best practice.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

JenniferRah
Mega Sage

Try this: 

 

enhancement.setValue("due_date", dmn_demand.requested_by.getLocalDate());

Thanks for your response but unfornately it doesn't work. If I add getLocalDate() the value directly is not moved ☹️

You may have to do this then:

var gd = new GlideDate(dmn_demand.requested_by);
enhancement.setValue("due_date", gd.getDisplayValue() + "00:00:00");

Ankur Bawiskar
Tera Patron
Tera Patron

@Leonel Sandroni 

this is bound to happen as you are setting date value to date/time field. you can set value in GMT using this

Set the value for hours minutes and seconds as 00:00:00

enhancement.setValue("due_date", new GlideDateTime(dmn_demand.requested_by + ' 00:00:00').getValue());

This will set the value as start of date in GMT but the value on form will be displayed as per logged in user's timezone

Also discuss with customer if they are ok to set value in GMT

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader