Workflow : How to put a task and RITM in pending if state is "open" during 1 day ?

SBT1
Tera Contributor

Hello,

 

I would like to know if it's possible in the workflow (not in a Business rule) of my catalog item to put a Task and the RITM in pending if state of the task is open since 1 day.

I have tried with cores "if", "Timer" and "Set Values" without any success.

 

Thank you for your help.

 

3 REPLIES 3

Moin Kazi
Kilo Sage
Kilo Sage

Hi @SBT1 ,

 

Yes, it can be implemented this in a ServiceNow workflow using a combination of timers and conditions. Here's an outline of the steps to achieve it:

  1. Task Activity: At the beginning of your workflow, include the task creation (for example, creating a task in open state and assigned to Database team or any custom task linked to the RITM). This ensures the workflow starts with tracking the task.

  2. Timer Activity: Add a timer right after the task activity. Set the timer duration to 1 day, which will trigger the next action after 24 hours.

  3. Condition Activity: After the timer, add a condition activity to check if the task state is still "Open." Define the condition in the workflow.

  4. Set Values Activity: If the condition is true (task is still open), use a "Set Values" activity to update both the task's and the RITM's state to "Pending."

By structuring the workflow this way, the system will automatically move the task and RITM to "Pending" if no action is taken on the task within a day.

 

 

Feel free to mark the solution as correct and helpful.

 

Best regards,
Moin

SBT1
Tera Contributor

Hello @Moin Kazi 

 

Thank you for your reply.

The workflow and tasks already exist.

My problem is when I put a condition, the condition 'State' is verified at RITM/Request level and not on task one. I encountered the same issue with core "Set Values" 

Do you have an idea how to modify this ?

Hi @SBT1 ,

 

To check the condition in a workflow running on the RITM table while verifying the task's state, you need to use scripted conditions or a condition activity that can evaluate task records related to the RITM.

Here’s how to achieve it:

  1. IF Condition Activity:

    • Use a scripted condition within the workflow.
    • In the condition script, query the related sc_task table (for tasks linked to the RITM).
    • Example script:

 

answer = ifScript();
function ifScript() {
    var taskGr = new GlideRecord('sc_task');
    taskGr.addQuery('request_item', current.sys_id); // RITM reference
    taskGr.addQuery('state', 'open'); // Check if any task is still open
    taskGr.query();
    if (taskGr.next()) {
        return 'yes'; // Task is still open
    } else {
        return 'no'; // No open tasks
    }
}

 

Please find below image- 

MoinKazi_0-1728915642665.png

 

If the script activity returns "yes," link it to your "Set Values" activity, which updates the state to "Pending." If it returns "no," no further action is needed.

 

Note: Ensure that these four activities are not set as the main activities; otherwise, if the script returns "no" and the subsequent activity is not linked, the workflow will fail.

 

 

Hope this help you.

 

Regards

Moin