Alternative for eval() in servicenow.

kavitha_cr
Mega Guru

Hi All,

I need to replace the eval() with glide script evaluator and below is the Script Include used in a Report to pull the records.

Script Include:

function CRA_Use(js, arg) {
var grq_ps = new GlideRecord('pa_scripts');
grq_ps.addQuery('name', js);
grq_ps.query();
if(grq_ps.next()) {
eval(grq_ps.script);
if(typeof CRA_JSF === 'function') {
if(typeof arg === 'undefined') { return CRA_JSF(); } else { return CRA_JSF(arg); }
} else if(typeof CRA_JSC === 'function') {
if(typeof arg === 'undefined') { return CRA_JSC(); } else { return CRA_JSC(arg); }
} else if(typeof CRA_JSO === 'function') {
if(typeof arg === 'undefined') { CRA_JSO(); } else { CRA_JSO(arg); }
}
}
}

Can anyone guide me in modifying the above script.

Thanks in Advance,

Shilpa.

9 REPLIES 9

Hi Justin,

It will be useful, if u can help me with modifying the above script.

Thanks,

Shilpa.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

function CRA_Use(js, arg) {
var grq_ps = new GlideRecord('pa_scripts');
grq_ps.addQuery('name', js);
grq_ps.query();
if(grq_ps.next()) {

var ret = GlideEvaluator.evaluateString(grq_ps.script);

if(typeof CRA_JSF === 'function') {
if(typeof arg === 'undefined') { return CRA_JSF(); } else { return CRA_JSF(arg); }
} else if(typeof CRA_JSC === 'function') {
if(typeof arg === 'undefined') { return CRA_JSC(); } else { return CRA_JSC(arg); }
} else if(typeof CRA_JSO === 'function') {
if(typeof arg === 'undefined') { CRA_JSO(); } else { CRA_JSO(arg); }
}
}
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

I tried the above script but when used this script in report I am not getting any records.

 

Thanks,

Shilpa.