OnLoad Catalog Client Script for Catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2018 09:49 AM
Hello All,
I have he following script used to auto populate department and company fields based on a user sys_id.
function onLoad() {
//Type appropriate comment here, and begin script below
var userID = g_user.userID;
if (g_form.getValue('comp') == '') {
var compID = '';
var userc = new GlideRecord('sys_user');
userc.addQuery ('sys_id', userID);
userc.query(processUserCompanyRequest);
}
if (g_form.getValue('department') == '') {
var departmentID = '';
var userd = new GlideRecord('sys_user');
userd.addQuery ('sys_id', userID);
userd.query(processUserDepartmentRequest);
}
function processUserCompanyRequest(user){
if (user.next()) {
compID = user.company;
g_form.setValue('comp',compID);
}
}
function processUserDepartmentRequest(user){
if (user.next()) {
departmentID = user.department;
g_form.setValue('department',departmentID);
}
}
}
The department field has no problem auto populating based on the user. When I tried an alert for the compID the returned message is undefined. The reference field in the user table is called company. Any ideas would be welcome as both department and company fields in the user table are references to there own respective tables.
Thanks in advance.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2018 02:00 PM
Thanks Sanjiv gs cannot be used in a client script.