- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2017 09:52 AM
I have a business rule that is used to set a lead time dateTime field based on the risk value. So if the risk level is a value of say 1 (high) the amount of days lead time to earliest start date is 14, or i f it is lower like say a value of 4 (low) the number of days to earliest start time would be 1 day. The earliest start date is calculated by the current DateTime + lead time days. The earliest start date gets entered as yyyy-mm-dd hh:mm:ss. As it stands this works just fine. . .until we add in a UI Action that evaluates the earliest start time again a start_date to be sure the start_date doesn't come before the earliest start date.
As long as the user's date format uses the yyyy-mm-dd hh:mm:ss format everything works fine, but if the users date format for the start_date is different then the evaluation doesn't work properly. So I believe I need to set the earliest start date format match the user's format.
My Business Rule code: (Please note this isn't my code it was created by someone else.)
// Compute lead time based on risk
if (current.risk == "1") {
current.lead_time="14";
} else if (current.risk == "2") {
current.lead_time="8";
} else if (current.risk == "3") {
current.lead_time="1";
} else if (current.risk == "5") {
current.lead_time="0";
}
// Get the current date time when a risk is updated
var gdt1 = new GlideDateTime(gs.nowDateTime());
// check if lead time is set and then add it to current date time
// Compute Earliest Start date = current date time + lead time
gdt1.addDaysLocalTime(current.lead_time);
current.earliest_start = gdt1.getValue();
Everything I have tried so far has failed to change the format. Any ideas?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2017 11:05 AM
The value "g_user_date_time_format" is client side only. As for the business rule, change this line
current.earliest_start = gdt1.getValue();
with
current.setDisplayValue("earliest_start", gdt1.getDisplayValue());
I believe that will fix your issue if I understand your issue correctly.
If it does not you are going to need to post a screen shot of what the user sees and some log statements to show what the system is returning.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2017 10:03 AM
If you are trying to do this on the Client you can use "g_user_date_time_format" to get the users date/time format to write your client script. On the Server side I'm reasonably sure you just need to do things like
current.setDisplayValue("start_time", gdt.GetDisplayValue())
and that will do things in the user time zone and format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2017 10:51 AM
I have tried the g_user_date_time_format without any luck. I have also tried the setDisplayValue but not in the same way you have it. Can you help me out just a little more with exactly where this would go, or how I should use it in my script? would it be more like...
current.setDisplayValue("Earliest_Start ", gdt.GetDisplayValue())= gdt1.getValue();
Sorry I am still a bit new to service now.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2017 11:05 AM
The value "g_user_date_time_format" is client side only. As for the business rule, change this line
current.earliest_start = gdt1.getValue();
with
current.setDisplayValue("earliest_start", gdt1.getDisplayValue());
I believe that will fix your issue if I understand your issue correctly.
If it does not you are going to need to post a screen shot of what the user sees and some log statements to show what the system is returning.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2017 12:36 PM
Great this mostly worked!!!!!!!!!!!! If the format uses a dash like "mm-dd-yyyy" but if it it uses anything else like "mm/dd/yyyy" or "mm.dd.yyyy" then it doesn't change to the correct format.