Script Include is returning object Object

Community Alums
Not applicable

Hi Team,

 

I have referred all the communites but not able to solve the problem.Below is my Script Include screenshot:

Ankur20_0-1714305084904.png

 

If you see below statement is printing proper values in the log:

gs.info('Account1 is:' + account.name);
   gs.info('Account1 is:' + account.sys_id);
 
But when I do 
 gs.info('Returned:' + JSON.stringify(accountList));   This is giving log as Returned:[{"name":{},"sys_id":{}}]
Therefore I am getting Null result or Object Object. 
Below is my Client Script SS:
I am doing proper parsing but of no help.
Ankur20_1-1714305459052.png

 


 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Community Alums ,

Please check below code it works for me 

var account = {};
var accList = [];

var inc = new GlideRecord('incident');
inc.addQuery('sys_id', 'ed92e8d173d023002728660c4cf6a7bc');
inc.query();
if(inc.next()){
	gs.print("here" + inc.caller_id);
	account.name = inc.caller_id.getDisplayValue();
	account.sys_id = inc.caller_id.toString();
	accList.push(account);
}

gs.print(JSON.stringify(accList))

 

I tried same in my PDI with incident table and caller field

Result 

SarthakKashya2_0-1714307570395.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

 

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

Hi @Community Alums ,

Please check below code it works for me 

var account = {};
var accList = [];

var inc = new GlideRecord('incident');
inc.addQuery('sys_id', 'ed92e8d173d023002728660c4cf6a7bc');
inc.query();
if(inc.next()){
	gs.print("here" + inc.caller_id);
	account.name = inc.caller_id.getDisplayValue();
	account.sys_id = inc.caller_id.toString();
	accList.push(account);
}

gs.print(JSON.stringify(accList))

 

I tried same in my PDI with incident table and caller field

Result 

SarthakKashya2_0-1714307570395.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

 

Narsing1
Mega Sage

On Line#93 of your client script, can you try like this.  It looks good to me except this line as using the same variable which is a string type and assigning an Object.

 

var b = JSON.parse(answer);

 

Thanks,

Narsing

Ashutosh C J
Tera Guru

Hi @Community Alums 
Dot-walking fields will not work as expected sometimes. Its better to covert them to string and then add it to the object
You can either use getDisplayValue(), getValue() or try adding an empty string ""

 

 

account.name = rel.company.name + "";
account.sys_id = rel.company.sys_id + "";