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.

Error in Background script

RFJ1
Tera Contributor

Hi,

I was testing this code in Bg Script and it was not executing getting the error ,

com.glide.script.RhinoEcmaError: "getRoles" is not defined.


Basically trying to pass user defined values to a function and check whether that record is present in the table or not.
var role_new = 'it_executive';
var user_new = '46efa3701b14f010a240ebd56e4bcbd4';
gs.info(getRoles(role_new,user_new));


getRoles: function(role,user)
{
var gr = new GlideRecord('sys_user_has_role');
gr.addEncodedQuery('role.name='+role+'^user='+user);
gr.query();
if(gr.hasNext())
{
return "found";
}
}

Any help on what is wrong is appreciated. Thanks:)

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Use

 

function getRoles(role,user) { var gr = new GlideRecord('sys_user_has_role'); gr.addEncodedQuery('role.name='+role+'^user='+user); gr.query(); if(gr.hasNext()) { return "found"; } }

View solution in original post

5 REPLIES 5

Thanks