Try to Order an item from custom cart orders but all items from default cart is being ordered


London and below



This is a bug in the platform and it has been addressed in PRB1297366


The OOB order_now API (api/sn_sc/servicecatalog/items/{sys_id}/order_now) is designed for ordering only a single item
For ordering multiple items, checkout(/api/sn_sc/servicecatalog/cart/checkout) or submit order (/api/sn_sc/servicecatalog/cart/submit_order) should be used.
But currently, there is a bug in the platform which orders all the items from the portal cart instead of the custom cart, if we order multiple items using checkout or submit order and a PRB1297366 was created for this issue and the Problem is in testing state.
So as a workaround, a custom web service can be created and can be used that in the apps outside of SN.
1. Please change the current application scope to "Service Catalog REST API" (the same scope where the OOB order_now scripted API is present)
2. Type "Scripted REST APIs" in the filter navigator and select the "Scripted REST APIs" under the "System Web Services"
3. Open the record with the name "Service Catalog API"
4. Under the "Resources" section (at the bottom), Open the record with the name "Buy Item" in a separate tab for reference.
5. Go back to the "Resources" section and click "new"
6. Give the following values for the fields:
Name : <your desired name> (e.g) Custom Order now
API Version: v1
Relative path: /items/{sys_id}/<your desired name> (e.g) /items/{sys_id}/custom_order_now
7. Under the script section, paste the following code:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var request_body = request.body.nextEntry();
var quantity = '' + request_body.sysparm_quantity;
var noValidation = (request_body.sysparm_no_validation == 'true');
var cartName = request_body.sysparm_cart_name;
if (!/^\+?([0-9]*)$/.test(quantity))
throw new sn_ws_err.BadRequestError("Invalid Quantity value");
request_body.sysparm_quantity = quantity;
var itemId = '' + request.pathParams.sys_id;
request_body.sysparm_id = itemId;
var catItem = new sn_sc.CatItem(itemId);
if (!catItem.canView())
throw new sn_ws_err.BadRequestError("Security constraints prevent ordering of Item");
if(!noValidation) {
var catUtil = new RestCatalogUtil();
if (!catUtil.checkMandatoryVariables(itemId, request_body.variables))
throw new sn_ws_err.BadRequestError('Mandatory Variables are required');
var cart;
//If cartName is undefined then it will be falsy
cart = new sn_sc.CartJS(cartName);
cart = new sn_sc.CartJS("cart_" +itemId);
request_body.sysparm_cart_name = "cart_" +itemId;
try {
return cart.orderNow(request_body);
}catch(e) {
throw new sn_ws_err.NotFoundError("Invalid Request");
})(request, response);
8. Save the record.
Now the custom scripted api can be found in the API list in the REST Explorer and it would order all the items from the custom cart.
Please make sure that this object {"sysparm_quantity":"1","get_portal_messages":"true","sysparm_cart_name":"JJ1234"} be included in the Request body.



Article Information

Last Updated:2018-10-15 07:22:01