addDays function not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 09:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 10:05 AM
Try the below code
var scheduledJob = new GlideRecord('sys_trigger');
scheduledJob.initialize();
scheduledJob.name = 'assign to Group B';
// Correcting the date calculation
var scheduledDate = new GlideDateTime(effectiveDate);
scheduledDate.addDaysLocalTime(-30);
scheduledJob.next_action = scheduledDate.getValue(); // Ensure correct assignment
// Assign the script to update the record
scheduledJob.script = 'var gr = new GlideRecord("' + tableName + '"); if (gr.get("' + triggerRecordSysId + '")) { gr.assignment_group = "' + groupB + '";gr.state=10; gr.update(); }';
scheduledJob.insert();
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Priyatam Patchipulusu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 11:43 AM
Thanks @priyatam_pvp Its working now, however the script is not getting executed. I manually changed the next action to 5 mins from now. waited for it to run, however the state is red "ready". It did not execute the script.
'var gr = new GlideRecord("' + tableName + '"); if (gr.get("' + triggerRecordSysId + '")) { gr.assignment_group = "' + groupB + '";gr.state=10; gr.update(); }';

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 10:52 AM
So how did you define the var "effectiveDate"? I do not see that in your code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 10:58 AM
Hi Drew, this is defined in a flow: