- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:12 AM
Hello,
I have a variable which will process date/time/am (or) pm in a seperate logic and push the calculated time into a var.
e.g., gs.log(patchStart) >> 03-08-2022 6:00 PM
Now i want to set this to a catalog item variable which is in RITM form.
When i try with below code. The value thus being set is either random number or takes +/- 1Hour.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2022 02:38 AM
Hello Kingstan,
You can try with the below script once to check if you are able to set the String field value into Date/time field
(function () {
var incoming = '28-08-2022 02:00 PM';
var incomingTime = "";
if (incoming.indexOf("AM") >= 0)
incomingTime = incoming.replace(" AM", ":00");
else
incomingTime = incoming.replace(" PM", ":00");
var gdt_incoming = new GlideDateTime(incomingTime);
gs.print(gdt_incoming);
if (incoming.indexOf("PM") >= 0)
gdt_incoming.addSeconds(12*60*60) // adding 12 hours if PM to convert in 24 hour time format
gs.print(gdt_incoming);
var numericValue = gdt_incoming.getNumericValue();
var gr = new GlideRecord("change_request");
gr.get("751f2f4097f1d5104cadfb000153af14")
gr.start_date.setDateNumericValue(numericValue);
gr.update();
})();
Please mark my respsone as helpful/correct, if it answer your question.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:21 AM
HI Kingstan,
Please refer to this link and make changes
How to set mm-dd-yyyy value from string to date field
Mark Correct or Helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 07:02 AM
I refered that already. It did not help me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 10:30 AM
Hi, Abhinay Erra.
Requesting your comment on this for me to solve this, Please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2022 02:38 AM
Hello Kingstan,
You can try with the below script once to check if you are able to set the String field value into Date/time field
(function () {
var incoming = '28-08-2022 02:00 PM';
var incomingTime = "";
if (incoming.indexOf("AM") >= 0)
incomingTime = incoming.replace(" AM", ":00");
else
incomingTime = incoming.replace(" PM", ":00");
var gdt_incoming = new GlideDateTime(incomingTime);
gs.print(gdt_incoming);
if (incoming.indexOf("PM") >= 0)
gdt_incoming.addSeconds(12*60*60) // adding 12 hours if PM to convert in 24 hour time format
gs.print(gdt_incoming);
var numericValue = gdt_incoming.getNumericValue();
var gr = new GlideRecord("change_request");
gr.get("751f2f4097f1d5104cadfb000153af14")
gr.start_date.setDateNumericValue(numericValue);
gr.update();
})();
Please mark my respsone as helpful/correct, if it answer your question.
Thanks