I have a scripted REST API to create REQ/RITM of a particular catalog, how do I modify REST Request Body before I create REQ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 05:10 AM
I have a scripted REST API to create REQ/RITM of a particular catalog, how do I modify REST Request Body before I create REQ?
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 05:24 AM
Can you provide some additional details around how you are doing this? Perhaps share the script from the scripted REST API?
What is it you want to modify in the request body? (not the response body, right?)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 05:55 AM
Hey Chuck,
I have a catalog item which has Variable Set with fields like (Requested_For, Phone, Line manager, cost center )....the third party tool will send the "name" of "Requested for".
Eg..
{
"sysparm_quantity":"1",
"variables":{
"s_name":"PhotoShop",
"e_ref_num":"SOF1234",
"requested_by":"Daileena Gomes",
"requested_for":"Joel Dsouza",
"phone_number":""
}
}
and in scripted rest API I am pulling Requested for SYS_ID and phone , line manger details from SYS_USER and want to set this values in REQUEST BODY...and then hit "cart.orderNow(request_body);"
currently the Scripted REST creates RITM and populated VARIABLES , however the REQUESTED FOR and REQUESTED BY will get populated only if I pass SYS_ID.
I am using code in "Buy Item " resource of Service Catalog REST API as baseline.
If not possible in Scripted REST, I am thinking of setting it once REQ is created via Business Rule, however need to check various ways I can do this and then use the best one.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 06:00 AM
Once you have the request body parsed out of your incoming request, it's an object that you a free to modify. If you need to inject another property in, you can do that. Sure.
Example:
var body = JSON.parse(request.getBody());
body.newItem = "My new item".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 04:22 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"
}
]
}