Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Scripted REST API dynamically send data as key values pairs in response body

Sowmya T
Tera Contributor

Hi Community,

As per our client requirement, I am trying to assign dynamic data as key value pairs in response body through scripted REST API. But I am getting error in REST API Explorer. Please find below screenshots for reference.

Any help would be appreciated!

Scripted REST API function:

calling this function in scripted API only:

find_real_file.png

Error in REST API Explorer:

POST test throgh REST exp - is the short description of the incident.

Here the problem is to assign the key dynamically to the response object.

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sowmya T 

Hi,

update line as this and it should work fine

obj[respFields[i]] = gr.getValue(respFields[i]);

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

Regards
Ankur

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Sowmya T 

Hi,

update line as this and it should work fine

obj[respFields[i]] = gr.getValue(respFields[i]);

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

Regards
Ankur

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