Change the date format to 'yyyy-mm-dd' even if user changes the profile date format to others

Sudheer961
Tera Contributor

It's a bi directional integration

 

we have a issue for planned start date and end date on change request

 

In rest message we have given query parameter as below for both planned start and end date

 

"u_end_date":"${u_end_date}",
"u_start_date":"${u_start_date}",

 

From the business rule we are trying to pass the current planned start and end date as below

 

r.setStringParameterNoEscape('u_start_date', current.getDisplayValue('start_date'));
r.setStringParameterNoEscape('u_end_date', current.getDisplayValue('end_date'));

 

The time format in the user profile will be set to default system format which is yyyy-MM-dd and the payload is going as "yyyy-MM-dd" which is fine

 

but whenever user tries to change to some other format which is dd-MM-yyyy, The payload values are 09-05-2024 going in this format which is creating a issue from the other instance, as there is a restriction from other instance that this format will not be acceptable since it is bidirectional integration.

 

 

Even if the user changes to any of the other format, But we want every time the payload for planned start and end date field should go as "yyyy-MM-dd" format. How can we achieve this

2 REPLIES 2

Maddysunil
Kilo Sage

@Sudheer961 

To ensure that the payload for the planned start and end dates always goes in the "yyyy-MM-dd" format, regardless of the user's preferred date format, you can try explicitly format the dates in the business rule before passing them to the REST message. Give it a try with below code:

 

// Get the planned start and end dates from the current change request
var plannedStartDate = current.start_date.getGlideObject().getDisplayValueInternal();
var plannedEndDate = current.end_date.getGlideObject().getDisplayValueInternal();

// Convert the dates to the "yyyy-MM-dd" format
var formattedStartDate = gs.dateGenerate(plannedStartDate).getDisplayValue();
var formattedEndDate = gs.dateGenerate(plannedEndDate).getDisplayValue();

// Set the formatted dates as query parameters in the REST message
r.setStringParameterNoEscape('u_start_date', formattedStartDate);
r.setStringParameterNoEscape('u_end_date', formattedEndDate);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

I just tried the above code, it is not working, to test the above code I changed system format to dd/MM/yyyy for testing. Then I triggered the business rule, then I could see the value in the payload for both planned start date and end date is "undefined".

"u_end_date":"undefined",

"u_start_date":"undefined",