order a catalog item

showsid02
Tera Contributor

How to order a catalog item from a background script.

 

please provide me the code.

2 REPLIES 2

Vishal Birajdar
Giga Sage

Hi @showsid02 

 

Please follow the answer provided by @Matthew Glenn 

 

https://www.servicenow.com/community/developer-forum/how-to-submit-a-catalog-item-from-script/m-p/17....

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

kamlesh13
Tera Contributor

Hey @showsid02,

 

Please find below script for your background script,

Do the needful changes as you query.

 

 

// Replace these variables with your specific values
var catalogItemSysID = 'your_catalog_item_sys_id';
var requestedFor = 'user_sys_id'; // The user for whom the item is being requested

// Create a request item (RITM)
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.setValue('cat_item', catalogItemSysID);
ritm.setValue('requested_for', requestedFor);
ritm.insert();

// Request fulfillment
var request = new GlideappCatalogRequest();
request.orderGuide = 'your_order_guide_sys_id';
request.items = ritm;
var requestId = request.placeOrder();

 

 

Regards,

Kamlesh