how to get the value from requestBody in scripted rest api

VIKASM535239375
Kilo Sage

how to get the value from requestBody in scripted rest api

Request Body in JSON:-

"RequestedFor": "Test.com",
"Status": "New",
"References": [
{
"DeltaId": "Test ID",
"DeltaModel": "Test Model",
"Region": "US",

}

]

 

Unable to fetch DeltaID and Delta Model

 

Even though getting the data in logs using gsinfo on refobj with below scripts

 

 var ref = request.body.data.References;
    var refobj = ref[0].DeltaId.toString();
 
gs.info(refobj);//It is working and providing DeltaId
 
But unable to push the value in Catalog Task Table even though other data is pushed in Catalog Task Table.
 
 
 
 
4 REPLIES 4

Muhammad Salar
Giga Sage

gs.info(refobj);//It is working and providing DeltaId
If is is working then you have DeltaId available in your variable.

Must be a issue with task script, show task script here

Zach N
Tera Guru

Hello!

From my brief testing, this has successfully returned the "DeltaId" value based on the JSON provided:

 

var deltaIdStr = request.body.data.References[0].DeltaId;

 

However, I should point out that the comma (",") after "Region": "US" in your request body should be removed.

 

Also, since gs.info(refobj); is returning the proper value, this likely indicates an issue with updating your Catalog Task. Can you provide your script for the REST Resource on you custom API? Which HTTP method are you using? Are you creating the task or just updating? I'm assuming ACLs aren't the issue since it appears your script is successfully executing the gs.info() line.

I am both inserting and updating the data in sc_tasks. we are using Post Method for Scripted Rest API.

Ah okay. Keep in mind that if you are updating records you will need to use Put instead of Post, as Post will insert new records only.

Can you sure your script for your Post method? It seems your script is successfully pulling the correct value from JSON body, so my guess the issue is with your update to the sc_task table.