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

How to use Business Rule to print to SCTASK worknotes and also to RITM additional comments

Jiajie Li
Tera Contributor

Hello Experts,

 

I have a Business Rule set to abort if user is requesting a software they already have. This BR is to prevent duplicate software entitlements. However, after the operation aborts I would like to notify the user that an abort was done. Is there a way to simple print a sentence to the SCTASK worknotes and to the RITM additional comments at the same time? 

 

Below is the full business rule script:

 

(function executeRule(current, previous /*null when async*/) {
    // Check for existing entitlement with the same software and licensee
    var gr = new GlideRecord('alm_entitlement'); //create a new GlideRecord to query "alm_entitlement" table
    gr.addQuery('assigned_to', current.assigned_to); //query the assigned_to field
    gr.addQuery('licensed_by', current.licensed_by); //query the licensed_by field
    gr.query();

    if (gr.hasNext()) { //checks if there is at least one record in the result set of the GlideRecord query. 
    //If there is a matching record, the hasNext() returns true, and the code inside the if statement is run.
        current.setAbortAction(true); //abort process
    }
})(current, previous);
4 REPLIES 4

Mohith Devatte
Tera Sage
Tera Sage

Hello @Jiajie Li ,

If they are requesting it via catalog item , when is this abort action happening is it after RITM has been created or exactly when ?

Hello @Mohith Devatte 

The abort action happens after RITM and SCTASK is created. When ITIL user selects a duplicate software in SCTASK and Close or Update then the abort action is triggered. 

Hello @Mohith Devatte 

Abort action happens when SCTASK is closed/updated. When user clicks Close or Update on the SCTASK, then it checks for duplicate. If there is duplicate, it aborts. 

 

Alex Tod1
Kilo Sage

Hello @Jiajie Li ,

 From what I understand, your br is triggered before insert, which is logical, in order to update SCTASK worknotes and to RITM I would recommend to create a script include and call him right before the line of code "current.setAbortAction(true)", you can send as a parameter current user so that later you can search for that records.