onAfter Business Rule isn't working as expected

Community Alums
Not applicable

Hey Everyone!

 

 

I'm trying to figure out what is causing my business rule to not work. 

 

It is an onAfter business that runs when the opened by field changes. If checks to see if the opened_by user has a internal role, and if so, it needs to map to another field internal_user, but it isn't mapping. Both fields are a reference fields consumer and internal_user. 

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here

    var gr = new GlideRecord("sys_user_has_role");
    gr.addQuery("user", current.opened_by);
    gr.addQuery("role", "7fcaa702933002009c8579b4f47ffbde"); //snc_internal role
    gr.query();

    if (gr.next()) {
        gr.internal_user = current.opened_by;
        
    } else {
        gr.consumer = current.opened_by;
        
    }

})(current, previous);
10 REPLIES 10

Community Alums
Not applicable

Thank you for your help, I had to do another query on the consumer user table.