Widget client controller is returned [object object]]

Tiasha
Tera Contributor

I am creating an incident when user enters the issue and clicks on create in portal widget but not able to display the incident number created using c.server.get(obj).then(function (response)....console.log is showing the correct incident number created but in client controller it is showing [object object]

1 ACCEPTED SOLUTION

Thanks, you can fix the issue by replacing the following server script 

data.incident = inc.number;

to

data.incident = inc.getValue('number');

 

If you print out the response.data object, you will notice something like the below:

JamesChun_0-1713778608163.png

You can see the value of the 'incident' key is an object.

 

I am not 100% sure why it works on the console.log but GlideRecord.field returns an object and that's why you need to use either field.toString() or getValue('field');

JamesChun_1-1713779154153.png

Cheers

View solution in original post

4 REPLIES 4

James Chun
Kilo Patron

Hi @Tiasha,

 

Can you share the widget's code?

Hard to see what you are doing without it.

 

Cheers

Tiasha
Tera Contributor

Tiasha_0-1713776945282.png

 

Thanks, you can fix the issue by replacing the following server script 

data.incident = inc.number;

to

data.incident = inc.getValue('number');

 

If you print out the response.data object, you will notice something like the below:

JamesChun_0-1713778608163.png

You can see the value of the 'incident' key is an object.

 

I am not 100% sure why it works on the console.log but GlideRecord.field returns an object and that's why you need to use either field.toString() or getValue('field');

JamesChun_1-1713779154153.png

Cheers

Community Alums
Not applicable

Hi @Tiasha ,

Can you please try to return like 

return JSON.stringify(yourVariable);

 

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

 

Thanks and Regards 

Sarthak