Illegal access error in workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 06:45 AM
Ive written the below code in an 'Approval - User' activity on a workflow. Its purpose is to pull users from a glide list field on the software table (the field itself is on the cmdb_ci table) and add them as approvers on a REQ task. However im getting this error: Illegal access to getter method getMessage in class org.mozilla.javascript.RhinoException
Please dont mock my code too much, im not a coder and most of my codes are frankensteins monsters from other bits of code people have written:
var r = new GlideRecord('sc_req_item');
r.addQuery('request',current.sys_id);
r.query();
if(r.next())
{
var Approvers = (r.Variables.please_select_the_software_you_would_like.u_sw_add_approvers) ;
}
{
answer.push = Approvers;
}
Thanks for any assistance.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2020 12:12 PM
Not sure if you're still experiencing this issue, but I stumbled across your post while investigating my own issues and noticed a few things:
- You haven't defined what "answer" is. You need to add "var answer = [];" in somewhere before you perform the push.
- You're defining "Approvers", but calling it out of scope. Might work, but not good practice. Approvers might not actually be needed.
- If you're expecting some results from the GlideRecord, you'll want to process everything in a while loop, including the push.
Try this (not tested)
var answer = [];
var r = new GlideRecord('sc_req_item');
r.addQuery('request',current.sys_id);
r.query();
while(r.next())
{
answer.push(r.variables.please_select_the_software_you_would_like.u_sw_add_approvers.sys_id.toString()) ;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2020 03:05 PM
I think you may have some items flipped around. A couple of questions:
1) What table is this workflow running on? is it a workflow tied to a catalog item?
2) If you are running it on the sc_request table and not sc_req_item what behavior do you expect when there are multiple items tied to a request?
3) Is the please_select_the_software_you_would_like variable a reference variable? If not, what kind of variable is it?
4) Is the u_sw_add_approvers field a field you added to your catalog item table? If it is, is it also a reference field?
A bit of sample code that will tell your Approval-User step in your workflow to use a value that is pulled from a variable when you run the workflow on a catalog item:
answer = [];
answer.push(current.variables.approver);
In this case, there is a reference variable on the catalog item called approver. Yours may look more like
answer = [];
answer.push(current.variables.please_select_the_software_you_would_like.u_sw_add_approvers);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 01:35 AM
Hi Olivier,
By the time you queried to the RITM record, The RITM might not be ready. add a timer activity before it and try it.
if you are doing this inside approver activity, you can write as follows,
answer = [];
answer.push(current.variables.please_select_the_software_you_would_like.u_sw_add_approvers.toString());
Mark ✅ Correct if this solves your issue and also mark ???? Helpful if you find my response worthy based on the impact.
Thanks,
Rama