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,

Did you check what is there in script?

check this link where I have shared an example

How to pass "current" dynamically within GlideEvaluator.evaluateString() as parameter..

Regards
Ankur

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

Hi @Ankur Bawiskar ,

 

The script is returning sysid's of recods.But when i am trying the above code I am getting as undefined.

 

Thanks,

Shilpa.

Please check the working example link I shared and try to enhance as per that

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

@Siva Jyothi 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

Carlos Candano
Mega Guru

Please refer to this API document for more information.

GlideScopedEvaluator