addDays function not working

dvelloriy
Kilo Sage
I am creating a new sys_trigger record and setting the next action based on effective date variable.
Effective data value is Apr 3, 2024. however when the flow is executed and sys_trigger record is created it shows current time stamp. Please advise.. I was expecting Mar 3, 2024.
 
var scheduledJob = new GlideRecord('sys_trigger');
    scheduledJob.initialize();
    scheduledJob.name = 'assign to Group B';
    scheduledJob.script = 'var gr = new GlideRecord("' + tableName + '"); if (gr.get("' + triggerRecordSysId + '")) { gr.assignment_group = "' + groupB + '";gr.state=10; gr.update(); }';
    scheduledJob.next_action = effectiveDate.addDaysLocalTime(-30);
    scheduledJob.insert();
 
dvelloriy_0-1740419644160.png

 

dvelloriy_1-1740419723579.png

 

 

 

8 REPLIES 8

I'm confused, you are logging out "rec.variables.effective_date", which you are not doing any adding of days to.

You say this is a flow but you are not providing enough information to really track things thru what you are doing.

 

I do agree with Animesh in that the system does not always like dates that are in the past and maybe altering the data before insert.

Animesh Das2
Mega Sage

Hi @dvelloriy ,

 

As you are trying to put a past date as the next run, which is logically wrong, the OOB BR, 'Ensure valid schedule' on 'sys_trigger' table might be getting triggered and setting the next run value as current time stamp.

Can you check if this BR is getting triggered with the help of some log statements.

 

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

Hi Animesh,

 

No its not the past date. Trigger action should always be in future. 

I am creating this trigger only when effective date is more than 30 days..

priyatam_pvp
Tera Guru

Try to Add a static future date from the script and see if you are facing any issues.

If it is inserted properly then the issue is with the date you passing.