Unable to set Due Date for sc_task

Tim Saunders
Tera Guru

I have a small script in a workflow step that should be setting the Due Date for a sc_task based on a variable value:

 

I can see that the "opened date" and the "new date" I'm incrementing to are what I expect but the sc_task shows only 4 days ahead, not the 8 I expected. I can't find a business rule that is firing and resetting the value; are there any OOB rules/scripts that could be doing this?

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Hi Tim,

There's a couple things here that you probably want to do differently, and perhaps some clarity.  The workflow is going to be running on the sc_req_item table, so whenever you use 'current' you are affecting the RITM.  So the first thing is that your script is updating the due_date field on the sc_req_item table, not the sc_task.  You'll also never, or at least rarely ever need current.update() in a workflow script as current.field_name = or current.setValue... will just do that and update without needing to specify it, so be including this you're causing an extra, unnecessary update.  Lastly, due_date, on either/both tables is a Date/Time type field, so by grabbing just the date you'll be throwing off the result by one day at certain times depending on your timezone offset to GMT.  All in all, your script to affect the Catalog Task that you are creating with this activity should look more like this:

   

var opened = current.variables.date_identified.toString();
var newDate = new GlideDateTime(opened);
newDate.addDays(8);
task.setValue('due_date', newDate);

 

Hi Brad,

 

Thank you for the advice. I didn't realize I was updating the RITM instead of the sc_task and I must have "current.update()" glued to the inside of my eyelids or something because I can't seem to stop typing it even when I know better.

 

 Regarding your solution, it's still not working for me. Not only does the due_date not get saved correctly to the sc_task but if I close the task the due_date value is updated (set further into the future) and I don't know what's doing that either. I can't find a BR or workflow step that should be messing with the date at all but it's got to be somewhere. Will post a solution if I ever find one.