The CreatorCon Call for Content is officially open! Get started here.

We have a scripted rest API post method which gets a request from another API, based on the request we get we have to do some validation (I used a script include by calling it from scripted rest api & tried to update some fields in a table.) it's not

krishna26
Kilo Expert

Hi,

Urgent Help

We have a scripted rest API post method which gets a request from another API, based on the request we get we have to do some validation (I used a script include by calling it from scripted rest api & tried to update some fields in a table.) but it's not working. it's not working when i tried to do the same thing by declaring the variables it's working fine.

Scripted Rest API : find_real_file.png

POST method

find_real_file.png

 

Script Include

find_real_file.png

Logs 

find_real_file.png

Table

 

find_real_file.png

find_real_file.png

I was wondering why the values are not being set on the table even the script is written correct. to check if the script works at all .... created a sampletest_pvk function . The same thing works i.e. values are set (from test_pvk function) .Could anyone help on this please 

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

same question has been asked on below thread. 

 

https://community.servicenow.com/community?id=community_question&sys_id=2a9524261bcb0810a59033f2cd4b...

 

answer has been mentioned on this thread. 

 

Kindly mark the answer as correct and close this thread. 

 

View solution in original post

5 REPLIES 5

Sateesh Kumar 2
Kilo Guru

Hello,

In your screpted REST API in line 3 replace 

request.body.dataString

with 

request.body.data

In your script include you are considering this parameter as JSON objeect not as string so from scripted REST API we need to pass object as well.

Regards,

Sateesh Kumar Devadoss

I have tried that as well but not working

Tony Chatfield1
Kilo Patron
Hi, not sure if I have fully understood but in line 7 of your script include you are encoding response_payload, perhaps this should be decode?

Harsh Vardhan
Giga Patron

same question has been asked on below thread. 

 

https://community.servicenow.com/community?id=community_question&sys_id=2a9524261bcb0810a59033f2cd4b...

 

answer has been mentioned on this thread. 

 

Kindly mark the answer as correct and close this thread.