Trying to create a RITM using scripted REST API

Pallavi65
Tera Contributor

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?

 

Pallavi65_0-1729249317759.jpeg

response.setBody(ar);    ------> this line of code is not captured in the screen shot, but this is there.

 

 

REST API Explorer:

Pallavi65_1-1729249405835.png

Note: I am these in the Query parameters:

customer     Application Services

Short description   Test 123

 

 

 

Please help

 

 

Regards,

Pallavi

 

9 REPLIES 9

Kieran Anson
Kilo Patron

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... 

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

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

GlideFather
Tera Patron

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! */