- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 04:42 AM
Continuing to my previous question,
I have a one date/time type variable in my catalog item which is displaying me date/time as per my catalog client script from which i have called a script include.
Now, its populating value like - 2022-08-02 04:13:17
I want this above in different format like- 2022-08-02T04:13:17+0000 (where T and +0000 remain same every time i'm getting this value)
please help me for this one and tell where i need to make changes
My script Include:
var AutoPopulateDate = Class.create();
AutoPopulateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDate: function() {
var daysrequired = this.getParameter('sysparm_days_required');
var currentDate = new GlideDateTime(gs.now());
currentDate.addMonths(daysrequired);
return currentDate;
},
type: 'AutoPopulateDate'
});
My catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert('Days Required change');
var ga = new GlideAjax('AutoPopulateDate');
ga.addParam('sysparm_name', 'getDate');
ga.addParam('sysparm_days_required', newValue);
ga.getXML(CallBackFunction);
function CallBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('return date '+answer);
g_form.setValue('date',answer);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 04:46 AM
You can try below
var result = answer .replace(" ", "T") + "+0000";
g_form.setValue('date',result);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 05:17 AM
If it's a date/time variable then it will always hold value in the system format and not in
2022-10-02T00:00:00+0000
check this link where I shared solution and try to enhance it further
How to convert current date time into ISO ISO8601 format: yyyy-MM-dd'T'HH:mm:ss'Z
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 05:11 AM
Hi,
the date format 2022-08-02T04:13:17+0000 looks like an ISO date/time format
So if you just replace it with T and 0000 it won't reflect the correct date/time
you can convert the normal date/time to that ISO format
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 05:16 AM
yes, by above way its not reflecting correct date/time format
can you please elaborate how to convert to that ISO format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 08:11 PM
Hi,
If it's a date/time variable then it won't hold data in any other format
So I am not sure if your requirement is still valid or not.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader