- 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 01:06 PM
How are you allowing them to give dates that have such a variety of formats? I think you need to restrict the user to picking from a few that you know will work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2017 01:12 PM
Yeah, that was decided long before me. I have a meeting planned to discuss with the team tomorrow. Thank you for the help!!!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2017 11:23 AM
Check if this works:
var gdt1 = new GlideDateTime(gs.nowDateTime());
gdt1.addDaysLocalTime(current.lead_time);
current.earliest_start = gdt1.getDisplayValue();