Need help to extract list of approvers to be shown in a dropdown list referencing a custom table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 07:27 PM
In my form, I have a custom "Approval Matrix" table which contains the following fields (with example):
UserID | Name | Level 1 Org Unit | Level 2 Org Unit | Position | Email Address | Approval Role | Cost Center ID | Cost Center Name |
EDDIE.FOO | Eddie Foo | Team Lead | EDDIE_FOO@GMAIL.COM | Team Lead | SSC_CC0024 | PROCUREMENT |
ALAN.GOH | Alan Goh | Chief Executive Officer | ALAN_GOH@GMAIL.COM | CEO | SSC_CC0178 | CAPABILITY DEVELOPMENT & INTEGRATION |
I inserted the UserID to be the same as UserID in sys_user table. Each user in sys_user table is assigned with a cost center.
Approval Role field contains roles such as CEO, Chairman, HOD, Chief, Team Lead, etc.
Cost Center ID corresponds to the Cost Center Code in the "Cost Centers" table.
I would like the list to execute the Scripts Include function onchange to retrieve the list of approvers that matches the following criteria from the "Approval Matrix" custom table:
1. Cost Center to match with requester's cost center from sys_user table
2. Approval role to match with predefined condition (e.g. Team Lead, HOD and Chief)
Based on the matching records found in Approval Matrix table, system to retrieve the corresponding users from sys_user table based on the UserID to show on the dropdown list in Record Producer.
Forgive me as I am new to scripting, I tried the following scripts in my scripts include but it failed to return results:
In the dropdown reference list, I select "Approval Matrix" table as reference and "Advanced" under Use reference qualifier. In the reference qualifier field, I inserted the script javascript: AORApprovalMatrix1().getApproverList();
in an attempt to call the script includes function.
Please assist me as soon as possible if you can. Thank you very much!
- Labels:
-
AOR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 02:18 AM
Hi @Karter83,
First of all, I wouldn't recommend creating a custom table for this. There is a limit on the number of custom tables you can create and most of the information in your custom table seems like it should be already available in the User [sys_user] table. Instead, I would recommend a few different approaches:
- Create Group records per 'condition'. i.e. Create a group called 'Team Lead Cost Center XYZ' and add the appropriate members to the group
- Use Decision Table
- Store the necessary information in the User record
Anyway, I will provide some feedback of your script.
//var requesterCostCenter = gs.getUser().getCompanyRecord().getValue('cost_center'); //not sure where you got this code, but there is no 'getCompanyRecord' function in GlideUser object - https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/GUserAPI#GUser-getID
var currentUser = new GlideRecord('sys_user');
currentUser.get( gs.getUserID());
var requesterCostCenter = currentUser.getValue('cost_center');
var approvalMatrixGr = new GlideRecord('approval_matrix'); //Are you sure this is the right name? If it's a custom table, normally the name is prepended with 'u_'
approvalMatrixGr.addQuery('approval_role', 'Team Lead'); //Also, are you sure it's the right column name? If it's a custom column, normally it's prefixed with 'u_'
approvalMatrixGr.addQuery('cost_center_id', requesterCostCenter); //Also, are you sure it's the right column name? If it's a custom column, normally it's prefixed with 'u_'
approvalMatrixGr.query();
var approvers = [];
while (approvalMatrixGr.next()) {
approvers.push(approvalMatrixGr.name.toString());
}
//approvers;
return approvers;
Is the 'Name' column in the custom table referencing the user table?
If so, you should change the reference list variable to reference the User [sys_user] table and use the reference qualifier there. Also, note that you don't have to use AJAX, and invoking the script include should be in the following format: javascript: 'sys_idIN' + new AORApprovalMatrix1().getApproverList();
That's a mouthful, best of luck. Cheers