- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2017 03:38 PM
Hello Experts,
I have a requirement where I need to populate a string field called "user" with the user's name as given in caller_id of the form if the user is VIP .
To achieve it , I tried to go ahead with the onchange script (as it a type of onload with some conditions) to invoke the glide ajax methods.
But before I go ahead , I wanted to verify if I can check using the background script that for the particular sys_id, whether I am able to get the user_name attribute on checking if the user's VIP value is true.
so this is the background script I worte :
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id','62826bf03710200044e0bfc8bcbe5df1');
gr.query();
if (gr.next()){
if(gr.vip == true){
return gr.user_name;
gs.print(gr.userName);
}else{
return null;
}
}
The javascript compiler says invalid return .
Need your guidance on this.
Thanks,
Rahamathullah
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2017 12:39 AM
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id','5b7c200d0a640069006b3845b5d0fa7c');
gr.query();
while(gr.next())
{
if(gr.vip == true)
{
gs.print(gr.user_name);
// return gr.user_name;
}
else{
// return null;
}
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2017 12:38 AM
return cannot be used in background script
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2017 12:39 AM
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id','5b7c200d0a640069006b3845b5d0fa7c');
gr.query();
while(gr.next())
{
if(gr.vip == true)
{
gs.print(gr.user_name);
// return gr.user_name;
}
else{
// return null;
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2017 01:32 AM
Try using onChange client script ..
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var caller=g_form.getReference('caller_id',getUserCheck);
}
function getUserCheck(caller){
if(caller)
{
var uname= caller.user_name;
var vp=caller.vip;
//alert(uname);
//alert(vp);
if(vp=='true')
{
g_form.setValue('u_user',uname);
}
}
}