Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

I am using this script in workflow , but i'm getting an error please check it?

1dusjhyahnt
Tera Contributor

Script :

 

function ifScript() {
    try {
        var ritmGR = new GlideRecord("sc_req_item");
        if (!ritmGR.get(current.sys_id)) {
            gs.error("Unable to get sc_req_item record with sys_id: " + current.sys_id);
            return 'error';
        }

        var user = ritmGR.variables.requested_for;

        // Check if the user has the 'itil' role
        var gr = new GlideRecord('sys_user');
        if (!gr.get(user)) {
            gs.error("Unable to get sys_user record for user: " + user);
            return 'error';
        }

        if (gr.hasRole('itil')) {
            return 'yes';
        } else {
            return 'no';
        }
    } catch (e) {
        gs.error("An error occurred: " + e);
        return 'error';
    }
}

// Call the function and store the result in the 'answer' variable
var answer = ifScript();

// Log the result to the script log
gs.info('Result: ' + answer);
5 REPLIES 5

VaishnaviShinde
Kilo Sage

Hello @1dusjhyahnt ,

 

Can please share the more details or your business requirement? Which type of error you are facing?

 

Regards,

Vaishnavi Shinde