Business Rule should run only when the user is logged in

Sonu Parab
Mega Sage
Hello All, I have created one br that consist of some script. But I want to run this br when user is logged in. Any help appreciated. Thank you
6 REPLIES 6

Mark Manders
Tera Patron

Please elaborate. What is your BR doing? What is the trigger? On what table is it running? 

Hello @Mark Manders ,
 we have one existing br on the cmdb_ci table, which prevents duplication of record creation.
table - cmdb_ci

before insert.
script :

(function executeRule(current, previous /*null when async*/ ) {
    var nodup = new GlideRecord('cmdb_ci');
    nodup.addQuery('name=' + current.name);
    nodup.query();
    if (nodup.next()) {
        gs.addErrorMessage("This will create a duplicate record,so insertion is aborted");
        current.setAbortAction(true);
    }
})(current, previous);

 

the aks is, run this br only when logged in user creates new record and one more thing we exclude for DISCOVERY, JAMF and SCCM integration.

@Sonu Parab , In the filter condition add created by is not with your integration profile and in the script condition add below piece 

gs.getSession().isLoggedIn()&& current. isNewRecord()

Regards,

shyamkumar

 

 

 

Hello @Sonu Parab,

 

BR will run explicitly on insert of cmdb_ci record. Hence by any source, as soon as record inserts, BR will run. hence your ask is already getting fulfilled here. I don't think you need more things to do in this case.

 

Please mark solution correct and helpful if this reply satisfies your query.

Thank You,

Rajesh