- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 10:50 PM
Not able to display value from script include
Please let me know what is wrong with the below code
I tried in background script with gs.print it worked
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld:function() {
var user_sysid = this.getParameter('sysparm_user_name');
gs.addErrorMessage( user_sysid); ----------------------- working
var getRecord = new GlideRecord('sys_user');
getRecord.query('sys_id',user_sysid);
getRecord.next();
var printvalue= getRecord.user_name;
gs.addErrorMessage(printvalue); ------------ not working
gs.log("print value "+printvalue); -------------- not working
return printvalue;
} ,
});
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 10:59 PM
Hi Suprakash,
Try adding if condition like below :
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld:function() {
var user_sysid = this.getParameter('sysparm_user_name');
gs.addErrorMessage( user_sysid); ----------------------- working
var getRecord = new GlideRecord('sys_user');
getRecord.query('sys_id',user_sysid);
if(getRecord.next()){
var printvalue= getRecord.user_name;
gs.addErrorMessage(printvalue); ------------ not working
gs.log("print value "+printvalue); -------------- not working
return printvalue;
}
} ,
});
Regards,
Ajay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 10:59 PM
Hi
This addErrorMessage will work on sys user table. Please check it there once.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 10:59 PM
Hi Suprakash,
Try adding if condition like below :
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld:function() {
var user_sysid = this.getParameter('sysparm_user_name');
gs.addErrorMessage( user_sysid); ----------------------- working
var getRecord = new GlideRecord('sys_user');
getRecord.query('sys_id',user_sysid);
if(getRecord.next()){
var printvalue= getRecord.user_name;
gs.addErrorMessage(printvalue); ------------ not working
gs.log("print value "+printvalue); -------------- not working
return printvalue;
}
} ,
});
Regards,
Ajay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 11:04 PM
Hi,
Small modifications required in the above code,
Below code will work.
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld:function() {
var user_sysid = this.getParameter('sysparm_user_name');
gs.addErrorMessage( user_sysid); ----------------------- working
var getRecord = new GlideRecord('sys_user');
getRecord.addQuery('sys_id',user_sysid);
getRecord.query();
if(getRecord.next()){
var printvalue= getRecord.user_name;
gs.addErrorMessage(printvalue); ------------ not working
gs.log("print value "+printvalue); -------------- not working
return printvalue;
}
} ,
});
Regards,
Ajay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2019 10:54 AM
Hi
thanks for the help got the issue
i tried with static sys_id its working but not with the variable.
its not able to do the query with variable user_sysid
but not sure why
its printing the value in
gs.addErrorMessage( user_sysid);
but failing in the query
getRecord.query('sys_id',user_sysid);