Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Reference Fields Showing Undefined in Scripted REST API

Lucky1
Tera Guru

Hello all,

 

I have created a SCRIPTED RESI API, and when clicked on "Explore REST API" related link from it, and when I give the sys_id of the group and Customer, in the logs it is giving undefined.

 

Lucky1_0-1747716605420.png

 

So, can you please help me in getting the values as the RITM is also not populating with the reference fields.

 

 

Regards,

Lucky

 

1 ACCEPTED SOLUTION

@Lucky1 

sorry but you didn't update the script as per what I shared

now that I know how request body looks, update as this and it will give you the value from JSON

var reqbody = request.body.dataString;

var parsedData = JSON.parse(reqbody);

var companyValue = parsedData.company_CM.toString();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@Lucky1 

how are you sending the json body? share that request body image or JSON here

also use this to parse, line 6 not required

var reqbody = request.body.dataString;

var parsedData = JSON.parse(reqbody);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur,

 

I am currently passing only one reference variable for testing purpose.

But when I open the RITM, in the variables section, the Customer (company_CM) variable is empty.

 

Lucky1_0-1747720730977.jpeg

 

Lucky1_1-1747720754749.jpeg

 

 

Regards,

Lucky

 

 

@Lucky1 

sorry but you didn't update the script as per what I shared

now that I know how request body looks, update as this and it will give you the value from JSON

var reqbody = request.body.dataString;

var parsedData = JSON.parse(reqbody);

var companyValue = parsedData.company_CM.toString();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Yes, great,

 

Need to add .toString()

 

Thanks a lot

 

 

 

Regards,

Lucky