Add 30 days to start time(date time field) and set stop time(date time field) on catalog form
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 09:32 AM - edited 12-28-2023 09:40 AM
Add 30 days to start time(date time field) and set stop time(date time field) on catalog form with user having different data format in profile other than system(MM-dd-yyyy).
catalog client script:
var ajax = new GlideAjax(script_include');
ajax.addParam('sysparm_name', 'add30days');
ajax.addParam('sysparm_start_date', newValue);
ajax.getXML(checkDate);
function checkDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('stop_time', answer);
}
script include function:
add30days: function() {
var stime= new GlideDateTime(this.getParameter('sysparm_start_date'));
stime.addSeconds(604800);
return stime;
},
The issue is with different date format on user profile, the above code is working fine for user with data format(system - OOTB) but not working if user has select other date formats(ex: dd/mm/yyyy) in profile. can you help in making the script working for all date formats in ServiceNow
Thanks in advance,,!
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 12:02 PM
Use case 2 can help you in this link
Please mark this response as correct or helpful if it assisted you with your question.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 02:07 PM
Hi ILAM,
In your script include, you can try the following:
// This should return the value using the current user's display format and time zone
return stime.getDisplayValue();
I hope my response has been helpful. If so, please consider marking it as such. Thank you!