- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 10:11 AM
Hi all ,
I have a requirement to create a reference field called 'OPID' referenced to sys_user table and a tex field called
'Name ' .
OPID field is auto populated when form loads ( did this by adding javascript:gs.getUserID(); to the default value of OPID field ) it works fine .
and wrote a onload client script to populate the name field based on whats in OPID field .
function onLoad() {
//Type appropriate comment here, and begin script below
var reqRec = g_form.getReference('u_opid');
var grUser = new GlideRecord('sys_user');
grUser.get(reqRec.sys_id);
g_form.setValue('u_name', grUser.name);
}
I wrote the same script for different catalog items and they all working fine but now the same script is throwing below error . How do i fix this ? Please suggest .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 01:18 PM
Correct. I would change your current onLoad script to an onChange script and use the default for the initial data. The onChange could look like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//skip when loading, the default value will do the trick instead
if (isLoading) {
return;
}
//clear the name when the reference field is cleared
if (newValue === "") {
g_form.setValue("u_name", "");
return;
}
var user = g_form.getReference("u_opid", showCallerName);
function showCallerName(user) {
g_form.setValue("u_name", user.name);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 12:46 PM
Hi Jim ,
your suggestion works for onload but
I need to write a onchagne cilent script as well , OPID field is editable so user can manually change to different name if they wants to .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 01:18 PM
Correct. I would change your current onLoad script to an onChange script and use the default for the initial data. The onChange could look like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//skip when loading, the default value will do the trick instead
if (isLoading) {
return;
}
//clear the name when the reference field is cleared
if (newValue === "") {
g_form.setValue("u_name", "");
return;
}
var user = g_form.getReference("u_opid", showCallerName);
function showCallerName(user) {
g_form.setValue("u_name", user.name);
}
}