- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2017 12:42 PM
I have the following script to assign the approver from a table(u_rfa_environments) field(u_approver)
Table = u_rfa_environments
Fied1 = u_environments
Field2 = u_approver
Here is the script
answer = [];
var app1 = current.variables.c_access_level;
var gr = new GlideRecord('u_rfa_environments');
gr.addQuery('u_environments', app1);
gr.query();
if (gr.next()) {
answer.push(gr.u_approver.toString());
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2017 05:02 AM
I think we've found the problem then. You're variable contains a sys_id which indicates that it's a reference field. Your Environments field is a string, which is likely to contain other values. There's a misalignment of data types.
I'm going to make an assumption here and figure that someone saw the display value in the variable (what gets shown to represent the record pointed to by the sys_id) and thought that is what they can use to get the proper record from the RFA Environments table. If that's the case, then try this (simple change to second line). It gets the display value instead of the sys_id from that variable. It's a bit like trying to find a record in table X that has a string "Chuck Tomasi" when all I have is a reference to my sys_user record (a sys_id.) If the getDisplayValue() returns "Chuck Tomasi", then I'm better off finding that record in table X.
Give it a try and let me know.
answer = [];
var app1 = current.variables.c_access_level.getDisplayValue();
var gr = new GlideRecord('u_rfa_environments');
if (gr.get('u_environments', app1)) {
answer.push(gr.getValue('u_approver'));
} else {
gs.error('Sorry, could not find a record in u_rfa_environments with u_environments set to: ' + app1);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2017 12:50 PM
What is the issue here Alfredo?
It appears you are trying to get a record based on the c_access_level variable. Are you sure it has a value? You could try forcing the type to a string and even shorten up the query a bit.
answer = [];
var app1 = current.variables.c_access_level.toString();
var gr = new GlideRecord('u_rfa_environments');
if (gr.get('u_environments', app1)) {
answer.push(gr.getValue('u_approver'));
} else {
gs.error('Sorry, couldn't find a record in u_rfa_environments with u_environments set to: ' + app1);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2017 01:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2017 01:18 PM
Alfredo, you are getting syntax error because of quotes in couldn't.
answer = [];
var app1 = current.variables.c_access_level.toString();
var gr = new GlideRecord('u_rfa_environments');
if (gr.get('u_environments', app1)) {
answer.push(gr.getValue('u_approver'));
} else {
gs.error('Sorry, could not find a record in u_rfa_environments with u_environments set to: ' + app1);
}
At each level, try to print out the values of variable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2017 03:41 PM
Sorry - two issues. I should not have used "shouldn't", the quote is messing up the string. Change that to:
gs.error('Sorry. Could not find a recor din u_rfa_environments with u_environments set to: ' + app1);
Also, you are missing the closing curly brace ( } ) on line 8. And of course, I forgot my disclaimer that the code was untested.
Updated script:
answer = [];
var app1 = current.variables.c_access_level.toString();
var gr = new GlideRecord('u_rfa_environments');
if (gr.get('u_environments', app1)) {
answer.push(gr.getValue('u_approver'));
} else {
gs.error('Sorry, could not find a record in u_rfa_environments with u_environments set to: ' + app1);
}