- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 03:45 AM
Hi All,
I want to update the field 'Planned End Date' with 'current DateTime + 4 hrs'. For this, I have used the below code:
var date = gs.nowDateTime();
var end= new GlideDateTime(date);
var hours = 60*60*4;
end.addSeconds(hours);
The issue is when I am using the above code then my 'Planned End Date' field get populated with 'current DateTime + 6 hrs'. It will automatically add 2 extra hours even though I am adding seconds according to 4 hrs.
My User's Timezone is in CET. I want the value according to user's timezone.
Could anyone tell me how to fix this issue?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 04:44 AM
Just try this
var gdt = new GlideDateTime();
var hours = 60*60*4;
gdt.addSeconds(hours);
gs.print(gdt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 03:58 AM
Hi,
Try below script, this should work for you.
var end= new GlideDateTime();
var hours = 60*60*4;
end.addSeconds(hours);
current.opened_at=end.getDisplayValue();
Please mark it correct/helpful based on the response.
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 04:14 AM
Hi Gaurav,
I have implemented the changes as you have mentioned but still I am facing the same issue. Below are the results:
Planned Start Date: 2018-04-20 13:08
Planned End Date: 2018-04-20 19:08
Thanks & Regards,
Mehak Arora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 04:26 AM
Hi,
I did it on my change_request fields i.e. start and end time.
Based on the value of start time, I have updated the end time which is what I think you are looking for.
Please try below script and see the action.
var gr = new GlideRecord("change_request");
gr.get('7a25a8750f5517401536715ce1050ea7'); //get the record
var startDate=gr.start_date; //get the start time
var gdt = new GlideDateTime(startDate);
gdt.addSeconds(14400); // no of seconds in 4 hours
gr.end_date=gdt.getDisplayValue();
gr.update();
Please mark it correct/helpful based on the response.
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 04:44 AM
Just try this
var gdt = new GlideDateTime();
var hours = 60*60*4;
gdt.addSeconds(hours);
gs.print(gdt);