Alternative for eval() in servicenow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 09:13 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 09:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2021 03:03 AM
Hi Justin,
It will be useful, if u can help me with modifying the above script.
Thanks,
Shilpa.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2021 03:11 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2021 04:26 AM
Hi
I tried the above script but when used this script in report I am not getting any records.
Thanks,
Shilpa.