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

Hi Kamil,

 

Ok, what if I want to insert a record on the Problem table with few reference fields and text fields.

How to write the script in the Scripted REST API, using POST method

 

Can you please give me the script?

 

 

Regards,

Pallavi

For PRB, there is no dependent relation like it is REQ-RITM, thus you can just insert it the way you have it in your screenshot in the first picture, just change the table from "sc_req_item" to "problem" and adjust the fields accordingly

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


No No, 

I tried it, it.s not coming.

I understand it has to be something in the object format and using JSON.Stringify method it will be taken into resposne body.

 

Regards,

Pallavi

Pallavi65
Tera Contributor

Hello all,

 

I have seen this link, to create a Service request from REST API Explorer.

 

Submit catalog request using Service catalog API - ServiceNow Community

My question is 

Can we do the same thing using Scripted REST API? If so, how?

Can you please explain me?

 

 

Regards,

Pallavi

Hi,

It is indeed possible to develop your own REST API; however, it is essential to have a comprehensive understanding of the Out-of-the-Box (OOB) table API. To gain this understanding, you should navigate to the Tables section within the Table Definition menu and familiarize yourself with the relationships of the OOB tables.

I would recommend against creating a custom API, as the OOB table API is designed to meet your needs effectively. I am uncertain about the rationale behind your desire to create a personal API.

Regards,
Suresh.