How to set Due date in Document Task

miro2
Mega Sage

Hi,

 

Does anyone know how to set a 'Due date' on the Document Task (sn_doc_task) when the task is created?

I haven't found any configuration for this, so I assume it needs to be scripted.

Has anyone worked on Document tasks and knows how to achieve this easily?

Thanks in advance.

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@miro2 Couldn't find an option to specify due date except the script. You can create an onBefore insert business rule on sn_doc_task table as follows to set the due date to 3 days after the task creation as follows.

 

(function executeRule(current, previous /*null when async*/) {
    // Check if due date is not already set
    if (!current.due_date) {
        // Create a GlideDateTime object for the current date
        var dueDate = new GlideDateTime();
        
        // Add 3 days to the current date
        dueDate.addDays(3);
        
        // Set the calculated due date on the task
        current.due_date = dueDate;
    }
})(current, previous);

Hope this helps.

View solution in original post

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@miro2 Couldn't find an option to specify due date except the script. You can create an onBefore insert business rule on sn_doc_task table as follows to set the due date to 3 days after the task creation as follows.

 

(function executeRule(current, previous /*null when async*/) {
    // Check if due date is not already set
    if (!current.due_date) {
        // Create a GlideDateTime object for the current date
        var dueDate = new GlideDateTime();
        
        // Add 3 days to the current date
        dueDate.addDays(3);
        
        // Set the calculated due date on the task
        current.due_date = dueDate;
    }
})(current, previous);

Hope this helps.

Hi @Sandeep Rajput 
Thank you for responding so quickly. Your solution worked perfectly.

cecil m
ServiceNow Employee
ServiceNow Employee

When you set up a participant on a document template, there is the option to use a document task template, and set the due date for the document task there.