How to send approval via workflow using script in approver activity in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2022 06:55 AM
For sending approval to approvers I'm using this method :
answer = [];
answer.push('id1');
answer.push('id2');
in id1 & id2 i'm sending the sys ids of the approver.
after executing this im receiving this error:
"Illegal access to getter method getMessage in class org.mozilla.javascript.RhinoException"
Please help me with this thanks in advance.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2022 07:09 AM
Hi
Can you try adding toString() as below?
var sysID = 'f0d6c17313daab84819a35739244b067' ;
answer.push(sysID.toString());
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Gunjan Kiratkar
Consultant - ServiceNow, Cloudaction
Rising Star 2022
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2022 07:10 AM
If that is not working then GlideRecord the user table and find sys_id of user and add it like below:
answer.push(grUser.getValue('sys_id'));
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Gunjan Kiratkar
Consultant - ServiceNow, Cloudaction
Rising Star 2022
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2022 08:37 AM
Try this :
var answer = [];
var sysID = 'fg0d6c17313jn56g4819a35739248a067';// change sysId according to your requirement
answer.push(sysID.toString());
Regards,
Imran Ahmad.
Please mark helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2022 09:34 AM
Your script must be doing something else, or this error is coming from somewhere else. This is saying an error is occurring when getMessage() is called, which should nothing to do with you pushing values to an array.
If you're pushing string values to an array, there's no need to call toString() because your values are already strings. The only time you have to use toString() is when the object you are passing is a reference, such as a GlideRecord field value.
For GlideRecord field values, it's best practice to use the getValue() and getDisplayValue() methods, which both return string values, so again no need to call the toString() function.
Now it looks like you're simply adding two string values to answer, and if that's the case, this looks to be an issue unrelated to your code. That said, rather than pushing these values to answer, can you try something like this? answer can bet set to a comma-separated string of sys_ids, or an array of sys_ids, so this should work for you just as well as adding to an array.
answer = (function () {
return 'sys_id_1,sys_id_2';
})();