Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

set a datetime variable for current DateTime to use the user's date format

tkh
Kilo Expert

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?

1 ACCEPTED SOLUTION

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.


View solution in original post

7 REPLIES 7

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.


Yeah, that was decided long before me.   I have a meeting planned to discuss with the team tomorrow.   Thank you for the help!!!!


Gowrisankar Sat
Tera Guru

Check if this works:



var gdt1 = new GlideDateTime(gs.nowDateTime());


gdt1.addDaysLocalTime(current.lead_time);


current.earliest_start = gdt1.getDisplayValue();