How to write scripted rest API to create RITM and pass field values and attachment using POSTMAN

Nikita47
Giga Contributor

How to write scripted rest API to create RITM and pass field values and attachment using POSTMAN.

 

 

Regards,

Nikita

 

7 REPLIES 7

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi Nikita,

you can use the following article as good example and arrange it as per your requirement:

https://snprotips.com/blog/2019/11/18/handling-textplain-and-other-unsupported-content-types-in-scri...

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nikita,

please find sample script which you can use in scripted rest api

Ensure you accept the variable information from the json request

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
 //add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('4054428fdb151f0097679ec6db9619c0', 1);

//fill in the variables on the request item form
cart.setVariable(item,"variable_1", "hello"); 
cart.setVariable(item,"variable_2", "test");

var rc = cart.placeOrder();

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request.number', rc.number);
ritm.query();
if(ritm.next()){

ritmNumber = ritm.number;

}

// return in response the REQ and RITM Number and status as success

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Thanks for replying. but my requirment is different. I want to pass RITM field values and attachment using POSTMAN. i am having difficulty in attachment while creating new RITM.

Hi Nikita,

Hope you have get the solution, can you please share.I have the same requirement.

TIA 🙂