How to use GlideScriptEvaluator to remove eval() method from the existing scripts?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 10:17 PM
1st Script:
var response1 = r.execute();
var response1 = r.execute();
var responseBody1 = response1.getBody();
var httpStatus1 = response1.getStatusCode();
var ans = (JSON) ? JSON.parse(responseBody1) : eval(responseBody1);
for (var i = 0; i < ans.length; i++) {
if (ans[i].usr_username == userID) {
str[j] = ans[i].app_pro_title.replace(/_|\-/, " ") + '-' + ans[i].app_number;
j++;
}
}
2nd Script:
var par = [];
for (var i=levelValue; i < gr.getValue("hierarchy_level"); i++) {
par.push(relationalColumn);
}
eval("var p = gr."+par.join("."));
how to remove these eval() executions and replace them with GlideScriptEvaluator.
how to remove these eval() executions and replace them with GlideScriptEvaluator.
Kindly help me regarding this 🙂
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 10:41 PM
Hi @nirwan_ritik ,
Creating an object for GlideScriptEvaluator you can use as below mentioned
var response1 = r.execute();
var responseBody1 = response1.getBody();
var httpStatus1 = response1.getStatusCode();
var scriptEvaluator = new GlideScriptEvaluator();
var ans = (JSON) ? JSON.parse(responseBody1) : scriptEvaluator.evaluateString(responseBody1);
for (var i = 0; i < ans.length; i++) {
if (ans[i].usr_username == userID) {
str[j] = ans[i].app_pro_title.replace(/_|\-/, " ") + '-' + ans[i].app_number;
j++;
}
}
var par = [];
for (var i = levelValue; i < gr.getValue("hierarchy_level"); i++) {
par.push(relationalColumn);
}
var scriptEvaluator = new GlideScriptEvaluator();
var script = "var p = gr." + par.join(".");
scriptEvaluator.evaluateString(script);
Please mark it as solution proposed and helpful if its serves your purpose.
Thanks,
Anand
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 10:44 PM
Hi Anand,
Thanks for the quick reply. I will execute this in my lower instances. I'll mark the solution helpful post execution. Will revert to you if I see any issues.
Thanks again 🙂