- 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-17-2017 03:42 PM
It will never reach the print statement if you put it after the return. It would need to go before the return.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2017 03:50 PM
still it says that invalid return
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2017 03:49 PM
- var gr = new GlideRecord('sys_user');
- gr.addQuery('sys_id','62826bf03710200044e0bfc8bcbe5df1');
- gr.query();
- if (gr.next()){
- if(gr.vip == true){
- gs.print(gr.user_name);
- }else{
- return null;
- }
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2017 12:12 AM
Hi, Sorry for the delayed response . This will not work for background script ,it will throw up the error saying "null value" . But the same can be used for ajax call . TO get the desired result,we actually need to use the function.