How to extract Object value(value is dynamic in nature) from Scripted Rest API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2017 12:39 PM
How to extract Object value from Scripted Rest API.example
JSON
{
"catItem":"Epic-Access Request",
"external_company":"SCH",
"external_ID" : "QAZ123456789012",
"variables" : [
{"What is your name":"ABC"}
{"What is FirstName":"A"}
{"What is your Lastname":"BC"}
]
}
Now every time Question (What is your name,What is FirstName,What is LastName) and Answer (ABC,A,BC) will change as per catalog item.
Therefore ,I need to retrieve values of both left side (Question) and right side (answer) in some run time variables to set in Request catalog variables.
I am writing a Scripted REST API as below and stuck as how to write logic for retrieving values of variables Object as it is dynamic in nature.Any response which leads to resolution will be highly appreciated.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var jsonObj = new JSON().decode(request.body.data);
gs.log(jsonObj); //Output object,Object
var catItem = request.body.data.catItem;
gs.log(catItem); ////Output Epic-Access Request
myObjAdd = new JSON().decode(request.body.data.variables);
for (var i in myObjAdd.Question) {
???????????????????
}
})(request, response);
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 04:15 PM
Hello,
I need to create a Webservice API where input is: Sys ID of any record and output is: all *related* active records to that sys id. The relationships between the tables is maintained in Relationships under system definition.
Could you please guide me how to implement this? Sample code would be great.
Input: Sys ID of the record
Output: All *RELATED* active records from *VARIOUS* tables (in the following JSON format):
{
"result": [
{
"Sys ID": "5520267",
"CI Name": "Record 1",
"Table Name": "u_table_a"
},
{
"Sys ID": "5520367",
"CI Name": "Record 2",
"Table Name": "u_table_a"
},
{
"Sys ID": "8331210",
"CI Name": "Record 1",
"Table Name": "u_table_b"
},
{
"Sys ID": "8321210",
"CI Name": "Record 2",
"Table Name": "u_table_b"
},
{
"Sys ID": "3042006",
"CI Name": "Record 3",
"Table Name": "u_table_b"
},
{
"Sys ID": "4509847",
"CI Name": "Record 1",
"Table Name": ""u_table_c"
}
{
"Sys ID": "4509247",
"CI Name": "Record 2",
"Table Name": ""u_table_c"
}
]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2018 11:02 AM
Rohith,
Did you figure this out by any chance? I'm trying to use object.values and object.entries, it only prints undefined always.