due_date in sc_task

Balakrishna_ABK
Tera Guru

How actual start, due date and actual end are calculated in sc_task table?

 

I want to set due date to 3 days after actual start by default 

Akhil7842_0-1698563064914.png

 

3 REPLIES 3

Anand Kumar P
Giga Patron
Giga Patron

Hi @Balakrishna_ABK ,
You have to write after insert business rule script on sc_task table

(function executeRule(current, previous ) {
    var actualStart = current.actual_start;
    var dueDate = new GlideDateTime(actualStart);
    dueDate.addDays(3);
    current.due_date = dueDate;
})(current, previous);

Please mark it as solution proposed and helpful if its serves your purpose.

Thanks,

Anand

Eswar Chappa
Mega Sage
Mega Sage

Hi @Balakrishna_ABK 

 

Below OOB business rule which are updating the actual start, due date and actual end on sc_task table

 

https://XXXXXXX.service-now.com/sys_script_list.do?sysparm_query=scriptLIKEwork_end%5EORscriptLIKEwork_start%5Ecoll...

 

For your requirement you need to update the below OOB Business to set end date after 3 days of start date.

 

https://XXXXXXX.service-now.com/sys_script.do?sys_id=bb21a570531320101d8fddeeff7b12c4&sysparm_view=&...

 Update the code in the above Business rule as below:

 

(function executeRule(current, previous /*null when async*/ ) {
    if (current.operation() == 'insert' || (current.operation() == 'update' && previous.state == -5)) {
        //run BR only when new sc_task is inserted in open/WIP state, or when sc_task is updated by moving state from pending to open/ WIP
        current.work_start = nowDateTime();
        var ed = new GlideDateTime(nowDateTime());
        ed.addDays(3);
        current.work_end = ed;

    }
})(current, previous);

 

Cheers, hope that helps

Eswar Chappa

*** Please mark as "Correct" or "Helpful" as appropriate ***

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Balakrishna_ABK ,

 

In the `sc_task` table in ServiceNow, the fields `actual_start`, `due_date`, and `actual_end` are typically managed based on various factors, including task dependencies, assignment rules, and user actions. However, you can customize the default behavior using Business Rules or UI Policies to set the due date to a specific interval after the actual start.

 

Here's how you can set the due date to 3 days after the actual start by default:

 

**Using a Business Rule:**

 

1. **Navigate to Business Rules:**

   - Go to `System Definition` > `Business Rules`.

 

2. **Create a New Business Rule:**

   - Create a new after insert Business Rule for the `sc_task` table.

 

3. **Write the Business Rule Script:**

   - Write a script to calculate the due date based on the actual start and set it to 3 days after the actual start.

   - Here's an example script (JavaScript syntax):

   

   (function executeRule(current, previous /*, gs*/) {

       // Check if actual start is set and due_date is not already set

       if (current.actual_start && !current.due_date) {

           // Calculate due date as 3 days after actual start

           var actualStart = new GlideDateTime(current.actual_start);

           actualStart.addDays(3);

           current.due_date = actualStart;

       }

   })(current, previous);

  

   - This script checks if the actual start is set and if the due date is not already set. If so, it calculates the due date as 3 days after the actual start.

 

4. **Save and Test:**

   - Save the Business Rule and test it by creating or updating `sc_task` records. The due date should be automatically set to 3 days after the actual start.

 

Ensure that the conditions and logic in the script align with your specific requirements and workflow. Test thoroughly in a non-production environment before deploying the Business Rule to your live instance.

 

Thanks,

Danish