- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2020 01:16 AM
Hi
I have 3 fields on my catalog item namely
1. Application (Reference to rec_application Table,drop down)
2.Level 1 user (Reference to sys_user Table)
3.Level 2 user (Reference to sys_user Table) so on selection of Application, Level1 and Level2 users should populate in the catalog item form
In Application we have user fields as primary user and secondary user
the primary owner should be mapped to Level1 and secondary user to Level2.
here is my script help me with changes:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var app = g_form.getValue('application');
var gr = new GlideRecord('rec_application ');
gr.addQuery('sys_id', app);
gr.query();
if(gr.next()){
g_form.setValue('level_1',gr.prim_own);
g_form.setValue('level_1',gr.sec_own);
}
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Service Creator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2020 01:22 AM
Hi,
It is not right to use GlideRecord in Client script, instead you can use the script below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ref = g_form.getReference('application', getApp);
}
function getApp(ref) {
g_form.setValue('level_1', ref.prim_own);
g_form.setValue('level_2',ref.sec_own);
}
Also in your script
g_form.setValue('level_1',gr.prim_own);
g_form.setValue('level_1',gr.sec_own); //this line should have level_2, but you have repeated level_1
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2020 01:22 AM
Hi,
It is not right to use GlideRecord in Client script, instead you can use the script below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ref = g_form.getReference('application', getApp);
}
function getApp(ref) {
g_form.setValue('level_1', ref.prim_own);
g_form.setValue('level_2',ref.sec_own);
}
Also in your script
g_form.setValue('level_1',gr.prim_own);
g_form.setValue('level_1',gr.sec_own); //this line should have level_2, but you have repeated level_1
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2020 01:31 AM
Hi,
Either use getReference() with callback or GlideAJax instead of GlideRecord
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2020 01:32 AM
Hi,
Script seems fine with jsut the variable level1 being set & not level2. What issue you are stuck with?
Also, as Anurag suggested it is not ideal to use GlideRecord() in client script. You can use getReference() or GlideAjax.