workflow for ritm> need to create workflow activity on if sctask is closed skipped

RBlor
Mega Guru

So, I have a workflow for a request item that creates catalog tasks. I would like to have the "IF" workflow activity to check if the sctask before it was closed skipped and if so follow the alternate path.  I have tried it and it doesnt seem to skip and follow the alternate path

 

// Check if the  SCTASK in this RITM is "Closed Skipped"
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id);
taskGR.addQuery('state', 4); // State 4 = Closed Skipped
taskGR.query();

if (taskGR.next()) {
    answer = true;
} else {
    answer = false;
}

 

 

RBlor_0-1740694037128.png

 

RBlor_3-1740694883910.png

 

 

 

14 REPLIES 14

@RBlor 

share your current script inside IF activity.

Did you check my below response?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
// For example,
//
//   answer = ifScript();
//
//   function ifScript() {
//      if (condition is true) {
//         return 'yes';
//      }
//      return 'no';
//   }
// Check if the  SCTASK in this RITM is "Closed Skipped"
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id);
taskGR.addQuery('state', 4); // State 4 = Closed Skipped
taskGR.query();

if (taskGR.next()) {
    return 'yes';
} else {
    return 'no'; 
}

@RBlor 

Please update your script as below.

 

// Check if the  SCTASK in this RITM is "Closed Skipped"

var taskGR = new GlideRecord('sc_task');

taskGR.addQuery('request_item', current.sys_id);

taskGR.addQuery('state', 4); // State 4 = Closed Skipped

taskGR.query();

 

if (taskGR.next()) {

    answer = ‘yes’;

} else {

    answer = ‘no’;

}

 

 

 

Medi C
Giga Sage

Hi @RBlor,

 

The script basically checks for any SCTAKS within the RITM which is "Closed Skipped". So if there is a SCTASK which is in other state (The screenshot does not show all workflow to see if there are other SCTASK created within the workflow), it will be queried and your script would return false. What you need to do is to:

  1. Add another query based on other fields which is unique on that specific SCTASK to make sure the query gets the right one checked. (Short description for example).
  2. Please use "yes" and "no" as returned values.

If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Ankur Bawiskar
Tera Patron
Tera Patron

@RBlor 

try this

answer = ifScript();

function ifScript() {
    // Check if the  SCTASK in this RITM is "Closed Skipped"
    var taskGR = new GlideRecord('sc_task');
    taskGR.orderByDesc('sys_created_on'); // this checks the latest task
    taskGR.addQuery('request_item', current.sys_id);
    taskGR.addQuery('state', 4); // State 4 = Closed Skipped
    taskGR.query();
    if (taskGR.hasNext()) {
        return 'yes';
    } else {
        return 'no';
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader