Make date/time value in format to MM/dd/yyyy hh:mm:ss and add 14 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-10-2023 01:47 AM
Hi All,
I have a requirement to create a scheduled job that will update all tasks without due date on cert_follow_task table and make it to 14days from the date of run of the job, but i have stumbled into an issue where the format is returning as yyyy-MM-dd hh:mm:ss i need it to be on format MM/dd/yyyy hh:mm:ss and use the addDays to add 14 days and update the due date, i have been trying to run it but unsuccessful, can anyone help me please??
var task = new GlideRecord('cert_follow_on_task');
task.addEncodedQuery('due_dateISEMPTY^active=true^stateNOT IN3,4,7^state=2^assigned_to=NULL');
task.query();
if (task.hasNext()) {
while (task.next()) {
var nd = new GlideDate();
var date = nd.getByFormat('MM/dd/yyyy hh:mm:ss');
var fd = new GlideDate();
var date2 = fd.getByFormat('MM/dd/yyyy hh:mm:ss');
date2.addDays(14);
task.due_date = date2;
task.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-10-2023 01:53 AM
hi @Suz Roque
See this developer page, also includes examples:
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=c_APIRef
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Sonia
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-11-2023 10:51 PM
Hi @Suz Roque ,
Below is the updated code you can give a try :
var task = new GlideRecord('cert_follow_on_task');
task.addEncodedQuery('due_dateISEMPTY^active=true^stateNOT IN3,4,7^state=2^assigned_to=NULL');
task.query();
while (task.next()) {
var date = new GlideDateTime();
date.addDays(14);
task.due_date = date.getDateFormatted('MM/dd/yyyy hh:mm:ss');
task.update();
}
Regards,
Shravan.
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-12-2023 07:35 AM
Hi Shravan,
Thank you for your reply, i have tried this code but it is not giving me anything. š
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-12-2023 08:41 AM
Hi Suz,
the following works for me:
var task = new GlideRecord('cert_follow_on_task');
//task.addEncodedQuery('due_dateISEMPTY^active=true^stateNOT IN3,4,7^state=2^assigned_to=NULL');
task.query();
while (task.next()) {
var date = new GlideDateTime();
date.addDays(14);
// task.due_date = date.getDateFormatted('MM/dd/yyyy hh:mm:ss');
task.due_date = date;
// task.update();
gs.info("New due_date = " + task.due_date + ".");
}
I commented out the encodedQuery as non of the records in my instance match. And I commented ou the task.update() as I don't want to update that field in my instance. seems 'getDateFormatted()' is not a valid function.