Trying to create a RITM using scripted REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 04:05 AM
Hello all,
I am trying to create a requested item, from the scripted REST API.
So, for this, I have created a Scripted REST API and I created a resource, with POST method and written a script.
After that, when I clicked on Explore REST API related link and tested it, the record is not getting created in RITM table and just giving 200 - Success message but not 201 message.
Can someone help me whats wrong here?
response.setBody(ar); ------> this line of code is not captured in the screen shot, but this is there.
REST API Explorer:
Note: I am these in the Query parameters:
customer Application Services
Short description Test 123
Please help
Regards,
Pallavi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 04:34 AM
You shouldn't be directly creating RITMs via GlideRecord due to their hierachical data model, and how flows/workflows attach. SN provide an OOB API to create requests (and the child ritm) https://developer.servicenow.com/dev.do#!/reference/api/xanadu/server/sn_sc-namespace/c_CartJSScoped...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 04:49 AM
Hello Kieran,
Understood.
So, can you tell me what is the script I can add in the POST method of Scripted REST API, to create a request first.
My Catalog item name is: Server Decommission
Variables inside it are:
Requested for (u_req_for)
Server to be decom (Reference field referencing to Server table)
Customer (Ref field)
and along with them, Short description and Description fields has to be filled up in the RITM.
Can you please help me?
Regards,
Pallavi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 04:58 AM
The orderNow function gives a good example of how you need to format your request.
Alternatively, the same API is made publically accessible via the Service Catalog REST API. If the source tool is able to format their payload, you won't need to create a scripted rest API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 04:42 AM
It might be due to the fact that RITM is ALWAYS associated with parent REQ, and eventually optional SCTASKs... try to create a record in "sc_task" rather than "sc_req_item" and eventually think of some pre-population from Request to Requested item
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */