- 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-07-2017 04:37 AM
Hi Chuck
I ran your code and I go this in the log
Sorry, could not find a record in u_rfa_environments with u_environments set to: 56bdda374fc33200505be9628110c73a
What do you think is happening?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 05:48 AM
Hi Alfredo,
Ah, that's a good sign. We've got a sys_id.
Next, go to the application menu filter and type:
u_rfa_environments.list
That will bring up a list of all your records. Use the filter to see if you can find a record where u_environments.
Environments | is | 56bdda374fc33200505be9628110c73a
Q: Is Environments a reference field? A string? A list field? What type is it? The plural indicates that it may be a list field, but I want to know for sure.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2017 09:13 AM
Thank you Chuck for your help
Environments is a string field, see below a screenshot of the three fields of my table u_environments.
A little background of my project. I'm creating a workflow to provide access to several environments. There are some that don't need approval and there are some that do. So after the user submits the request, I want to check if the environment has an approver, if it does, I want the approval task assign to that approver.

- 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-08-2017 05:53 AM
Thank you Chuck, that script is working perfectly