The CreatorCon Call for Content is officially open! Get started here.

Business Rule condition based on Task's parent Request Item?

Wesley Breshear
Tera Expert

Hello,

Struggling to find the right condition rule on an OOB Business Rule.   I would like to add an additional condition to OOB 'Cancel Workflows Upon Cancellation' business rule so that one of our Catalog Item's workflow doesn't get canceled when the Task is set to 'Closed Incomplete'.   This is because that catalog item has input values that have been entered by other task stages, and the final task is updating these values to the record of the table.   So keeping these values in place and then finally updating the record is preferred than stopping the workflow and losing all the inputted values.   I have created workflow conditions to notify admins when the user has canceled the task, but the business rule doesn't allow the workflow to proceed and immediately stops its progress. This only needs to occur for 1 catalog item, so all other catalog workflows can be canceled when the user selects "Closed Incomplete" for the task; basically a cancel workflow action due to this BR.

Current Condition: (current.getTableName() != 'sysapproval_group') && (current.getTableName() != 'rm_story') && (current.getTableName() != 'incident') && (current.getTableName() != 'problem') && (current.state.changesTo(4))

So I need the condition to look at the Task's current Request Item (parent) and determine it is not equal to this sys_id (706957260f873100cfaf059ce1050e5f).   Does anyone know how to set this condition?   I have tried a few get parent. statements with no success.

If not, is there a way in the script of this BR to exclude the specific catalog item?   I am still learning JavaScript, and even with the script below, I am not understanding how the workflow(s) are getting canceled.   I see the function is called but inside the function, the IF statements look like the should only do a gs.addInfoMessage.   I am missing where the command cancels the workflow?   Does just setting the variable (var) execute the action? (i.e., var numCnxd = workflow.cancel(current); )

/**

Service-now.com

Description: If task state changes to closed incomplete (4), cancel related workflows so we don't keep tasks active

**/

cancelMyWorkflows();

function cancelMyWorkflows() {

    //get workflow helper

    var workflow = new Workflow();

    //cancel all my workflows

    var numCnxd = workflow.cancel(current);

    if (numCnxd > 1)

          gs.addInfoMessage(numCnxd + " " + gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));

    else if (numCnxd == 1)

          gs.addInfoMessage("1 " + gs.getMessage("Workflow for {0} has been cancelled", current.getDisplayValue()));

}

Thank you,

-Wesley

3 REPLIES 3

ruzzty06
Tera Expert

current.request_item!=706957260f873100cfaf059ce1050e5f


Hi Rustly,



Good Day



Please add the quotes in the condition while checking for specific condition.



current.request_item!='706957260f873100cfaf059ce1050e5f';



Hope it helps you



Thanks,


Priyanka R


PriyaRanji
Tera Guru

Hi Wesley,



Good Day  



Case 1 : Yeah, you can do it in the below way for excluding the specific catalog item.



Please add the below code in the condition of BR :



current.request_item.cat_item!='Your Catalog Item sys-id which needs to be excluded';



Case 2 : To check the condition to look at the Task's current Request Item (parent)



Please add the below code in the condition of BR :



current.request_item != '706957260f873100cfaf059ce1050e5f';



Hope it helps you out  



Please mark it as correct/helpful/like based on the impact of the response.



Thanks,


Priyanka R