- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2017 12:47 PM
In one of our Service Catalogs, we have variable that is set to a Date Picker. In our workflow, the variable is copied over to a custom field we added to our Request Item table. That script looks like this:
var dteServiceNeeded = current.variables.DateServiceNeeded;
current.u_date_service_needed = dteServiceNeeded;
So when I test it out, and view the custom field on my Request Item table, it always shows whatever date I have chosen with a time component of 8:00 PM (not sure why it is picking that time).
So, I have a few question regarding this time piece:
1. How can I remove it, so it does not have a time component (or has a time component of 12:00 AM)?
2. How can I change it to use some other pre-determined time (like if I want them all to day 6:30 AM going forward)?
It is not a matter of just "hiding" the time component through formatting. I actually need it removed/changed, as it may be used in some calculations.
I found some old discussions that talked about using g_form.GetDisplayValue along with the Split function, but they only seemed to return errors for me.
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2017 12:27 PM
Hi Joe, the below script gets the time zone offset and adds to the variable and updates to the field.
I just remember the problem i faced some time back between the variable date and field date, variable dates are stored as UTC , while the field dates are stored in
local time zone.
The below script works fine, tested:)
var gdt = new GlideDateTime(gr.variables.date.toString())
// get the timezone offset in milliseconds and adds to your time value, this gives you the midnight time of the date picked in variables
gdt.add(gdt.getTZOffset()*(-1));
var myTime = new GlideTime();
// here you add the time you need to custom add
myTime.setValue("16:44:00");
gdt.add(myTime);
// update the field value
gr.u_datetime = gdt;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2017 01:08 PM
Hi Joe,
What is the data type of the u_date_service_needed field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2017 01:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 05:23 AM
Thanks for the reply Karthick.
Changing the data type would work if we don't care about the time piece at all, but would not accommodate the second item I listed in my original question, where we want to set it to some specific time.
In a nutshell, there may be some instances in which we care about the time, and others that we don't. So I am just trying to figure out how I can program that to change the time portion.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 12:06 PM
Hi Joe,
You can update the time on the field by GlideTime() API
The below script will update the time on the gliddate object to 06:45:20, you can replace that with the time you are looking for. You may need to look at the time zone offset too.
var gdt = new GlideDateTime(gr.variables.date);
var mytime = new GlideTime();
mytime.setValue("06:45:20");
gdt.add(mytime);
gs.print(gdt.getValue());