Not able to print value in log using script include

suprakash
Giga Expert

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;
} ,

});

1 ACCEPTED SOLUTION

Ajaykumar1
Tera Guru

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

View solution in original post

6 REPLIES 6

Omkar Mone
Mega Sage

Hi

This addErrorMessage will work on sys user table. Please check it there once. 

Ajaykumar1
Tera Guru

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

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

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);