We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

Sowmya T
Kilo Expert

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

@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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader