- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2019 08:35 AM
Creating a form with an independent Application and I'm getting the following error.
I have the following onChange client script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below...
var gr = new GlideRecord('sys_user');
if (gr.get(newValue)) {
g_form.setValue('u_email_address', gr.email);
// g_form.setValue('u_sec_email_address', gr.u_email);
}
}
I have also gone and created under the sys_properties.list a new
What am I missing? Obviously, I have other forms that work when the application is Global. I have also toggled the "Isolate script" without success.
Thanks.
Jason
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2019 09:28 AM
Try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var requestedfor = g_form.getReference('caller_id', getDetails); //Callback
function getDetails(requestedfor) {
if (requestedfor)
g_form.setValue('u_email_address', requestedfor.email);
g_form.setValue('u_x_ucid', requestedfor.u_ucid);
}
//Type appropriate comment here, and begin script below...
//var gr = new GlideRecord('sys_user');
//if (gr.get(newValue)) {
// g_form.setValue('u_email_address', gr.email);
// g_form.setValue('u_sec_email_address', gr.u_email);
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2019 08:48 AM
Best practice is to avoid using GlideRecord in a client script. I would suggest using a Callback script to accomplish this if the field you working off of is a Reference Field.
Here is one we use to load the initials, department, and user_id for a person chosen in the reference field Requested For:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var requestedfor = g_form.getReference('requested_for', getInitials); //Callback function is getInitials this allows the browser to continue to run through the script.
function getInitials(requestedfor) {
if(requestedfor)
g_form.setValue('requested_for_initials', requestedfor.u_initials);
g_form.setValue('requested_for_department', requestedfor.department);
g_form.setValue('requested_for_userid', requestedfor.user_name);
}
}
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2019 09:24 AM
Thanks Steven,
Does the following look correct? The commented out below if for comparison and will be deleted if correct.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var requestedfor = g_form.getReference('caller_id', getDetails); //Callback
function getDetails(callerid) {
if (callerid)
g_form.setValue('u_email_address', gr.email);
g_form.setValue('u_x_ucid', gr.u_ucid);
}
//Type appropriate comment here, and begin script below...
//var gr = new GlideRecord('sys_user');
//if (gr.get(newValue)) {
// g_form.setValue('u_email_address', gr.email);
// g_form.setValue('u_sec_email_address', gr.u_email);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2019 09:25 AM
Well, it didn't error out, but also didn't load any information.
Jason
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2019 09:28 AM
Try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var requestedfor = g_form.getReference('caller_id', getDetails); //Callback
function getDetails(requestedfor) {
if (requestedfor)
g_form.setValue('u_email_address', requestedfor.email);
g_form.setValue('u_x_ucid', requestedfor.u_ucid);
}
//Type appropriate comment here, and begin script below...
//var gr = new GlideRecord('sys_user');
//if (gr.get(newValue)) {
// g_form.setValue('u_email_address', gr.email);
// g_form.setValue('u_sec_email_address', gr.u_email);
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks