The CreatorCon Call for Content is officially open! Get started here.

Add 30 days to start time(date time field) and set stop time(date time field) on catalog form

ilam334
Tera Expert
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

SanjivMeher
Kilo Patron
Kilo Patron

Use case 2 can help you in this link

 

https://www.servicenow.com/community/in-other-news/auto-populating-and-validating-date-fields/ba-p/2...

 


Please mark this response as correct or helpful if it assisted you with your question.

Isaias H
Tera Guru

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!