- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 11:42 AM - edited 05-31-2023 11:43 AM
Hello All,
I have an requirement to create/order Multiple Items as part of our intergation and this is going to be an Inbound Integration , we have 5 items
order laptop
Access to VPN
order Mobile
Order ID
Order keyboard - in this Item I have to set predefined variable values
1. Automatic key board - choice to Yes
we cannot do this as order guide , we need to create as Individual request
So now I need to create 5 Items via Rest API can you please suggest some solution and Sample script ,
@Ankur Bawiskar @Voona Rohila @jaheerhattiwale
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 08:59 PM
I believe you want all 4/ 5 RITMs in same REQ
I created blog for this couple of years ago. have a look
If it helps please mark the blog as helpful
Multiple RITMs in same Request Using CartAPI
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 10:53 PM
@Michael51 Create a scripted rest api to add the custom code to it and trigger the api from outside the servicenow as you wish.
Send the Request body to the api like below
[
{
"catalog_item_sys_id": "<order laptop CAT ITEM SYS ID HERE>"
},
{
"catalog_item_sys_id": "<Access to VPN CAT ITEM SYS ID HERE>"
},
{
"catalog_item_sys_id": "<order Mobile CAT ITEM SYS ID HERE>"
},
{
"catalog_item_sys_id": "<Order ID CAT ITEM SYS ID HERE>"
},
{
"catalog_item_sys_id": "<Order keyboard CAT ITEM SYS ID HERE>",
"<Automatic key board VARIABLE NAME HERE>": "Yes"
}
]
Steps:
1. Go to "Scripted rest api" module
2. Create new scripted rest api
3. Scroll down to see the related list
4. create a new scripted rest resource
5. Add below code to scripted rest resource
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var requestBody = request.body.data;
for (var i = 0; i < requestBody.length; i++) {
var cart = new Cart();
var item = cart.addItem(requestBody[i].catalog_item_sys_id);
var keys = Object.keys(requestBody[i]);
for (var j = 0; j < keys.length; j++) {
if (keys[j] != "catalog_item_sys_id") {
cart.setVariable(item, keys[j], requestBody[i][keys[j]]);
}
}
var placeOrder = cart.placeOrder();
}
})(request, response);
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 08:11 AM
@Michael51 Use CartJS api to solve this.
Use addToCart function.
Documentation: https://developer.servicenow.com/print_page.do?release=rome&category=null&identifier=c_CartJSScoped&...
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2023 02:53 AM - edited 06-05-2023 07:17 AM
Hello @jaheerhattiwale , @Ankur Bawiskar
- How can I enhance following script to create this logic
also just confirming they just send requested for in the payload , remaining everything we need to handle in the logic , can you help me here var catalogItem = 'b70c34e807334c10540bf2508c1ed073'; // catalog item sys_id var jsonArray = [{"requested_for":"Abel Tuter","requested_by":"Sam Jone","model":"Hyundai","quantity":1,"device_model_name":"Car-Petrol"},{"requested_for":"Fred Luddy","requested_by":"Amy Jone","model":"Honda","quantity":1,"device_model_name":"Car-Diesel"}]; var cartId = GlideGuid.generate(null); var cart = new Cart(cartId); for(var i=0;i<jsonArray.length;i++){ var jsonObj = jsonArray[i]; var parser = JSON.parse(JSON.stringify(jsonObj)); var item = cart.addItem(catalogItem,1); cart.setVariable(item, 'requested_for', parser.requested_for); cart.setVariable(item,'requested_by',parser.requested_by); cart.setVariable(item,'model', parser.model); cart.setVariable(item,'quantity', parser.quantity); cart.setVariable(item,'device_model_name', parser.device_model_name); } var rc = cart.placeOrder(); gs.info('Request Number is: ' + rc.number);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2023 07:47 AM
I might have missed the earlier discussion.
Can you share what's your new requirement?
I would recommend raising another question as this is already answered.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2023 09:34 AM
Hello Ankur,
I need to create Single request with Multiple RITMS but not for same item its for each different item
your solution works for similar Item but need some help in enhancing for different items