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.

How to call an 'If' condition by creating system property for the same

Amrit4
Tera Guru

I have a script include with an 'if' condition. I want to call this condition by using system property. I mean I want to create a system property for this condition and then call this 'if' condition via that system property. Would be grateful if someone  gives me a detailed answer.

 

var ACLRestrictions = Class.create();
ACLRestrictions.prototype = {
initialize: function() {},

myFunction: function() {
if (gs.hasRole('admin') || gs.hasRole('itil_admin') || gs.hasRole('itil') || gs.hasRole('public') || gs.hasRole('snc_platform_rest_api_access')|| gs.hasRole('rest_service')|| gs.hasRole('kubernetes_discovery_api')|| gs.hasRole('approver_user')) {

//show full record

} else {
var uID = gs.getUserID();
var uGR = new GlideRecord("sys_user");
uGR.get(uID);

var q = current.addQuery('manager', uGR.manager);
}
},
type: 'ACLRestrictions'
};

1 ACCEPTED SOLUTION

oharel
Kilo Sage

Hi,

Why not just create the property as a string and call it?

Property:

name: myIfCondition

type: string

value: gs.hasRole('admin') || gs.hasRole('itil_admin') || gs.hasRole('itil') || gs.hasRole('public') || gs.hasRole('snc_platform_rest_api_access')|| gs.hasRole('rest_service')|| gs.hasRole('kubernetes_discovery_api')|| gs.hasRole('approver_user')

and then in your script:

if(gs.getProperty('myIfCondition') {

//some action...

}

 

harel

View solution in original post

1 REPLY 1

oharel
Kilo Sage

Hi,

Why not just create the property as a string and call it?

Property:

name: myIfCondition

type: string

value: gs.hasRole('admin') || gs.hasRole('itil_admin') || gs.hasRole('itil') || gs.hasRole('public') || gs.hasRole('snc_platform_rest_api_access')|| gs.hasRole('rest_service')|| gs.hasRole('kubernetes_discovery_api')|| gs.hasRole('approver_user')

and then in your script:

if(gs.getProperty('myIfCondition') {

//some action...

}

 

harel