Order a Service Catalog Item from a Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 05:27 AM
So, I yanked this script from this wiki page: Order a Service Catalog Item from a Script. It does exactly what I want it to do and I absolutely love it, but I have one issues. I have put this script in a run script activity in my workflow for Capital Project Request. When it runs, it is supposed to order a Capital Expense Request. The issue is, if I put in two Capital Project Requests one after another, the second Capital Project Request orders a Capital Expense for the first Capital Project Request again.
Basically...
I submit Capital Project #1 SCRIPT IN THE WF----> Capital Expense Created
Project Name: Redo parking lots Project Name: Redo parking lots
Start Date: 12-12-2017 Start Date: 12-12-2017
Estimated Amount: $300,000.00 Estimated Amount: $300,000.00
I submit Capital Project #2 SCRIPT IN THE WF----> Capital Expense Created
Project Name: Build Parking Garage Project Name: Redo parking lots
Start Date: 10-04-2019 Start Date: 12-12-2017
Estimated Amount: $950,000.00 Estimated Amount: $300,000.00
Any ideas what in this script would need to be changed??
Any help would be greatly appreciated!!
Here is the script for quick reference...
// nuke the current cart
nukeCart();
// new cart
var realCart = getCart();
var cartID = realCart.sys_id;
// order a blackberry
addToCart(cartID, "e2132865c0a8016500108d9cee411699", 1);
addOptions(cartID);
doOrder();
function addToCart(cartid, cat_item, quantity) {
var gr = new GlideRecord('sc_cart_item');
gr.initialize();
gr.cart = cartid;
gr.cat_item = cat_item;
gr.quantity = quantity;
gr.insert();
}
function addOptions(cartID) {
// Get the Cart Item
var kids = new GlideRecord('sc_cart_item');
kids.addQuery('cart', cartID);
kids.query();
if (kids.next()) {
// Look up the options for the item in the cart
var options = new GlideRecord('item_option_new');
options.addQuery('cat_item', kids.cat_item);
options.query();
// Add the appropriate Item Options
while(options.next()) {
var gr = new GlideRecord('sc_item_option');
gr.initialize();
if(options.question_text == "Is this a replacement for a lost Blackberry device ?") {
gr.item_option_new.setValue(options.sys_id);
gr.value = "No";
}
else if(options.question_text == "If it is a replacement, what was the original phone number ?") {
gr.item_option_new.setValue(options.sys_id);
gr.value = "(858)345-1418";
}
else if(options.question_text == "Special Requirements") {
gr.item_option_new.setValue(options.sys_id);
gr.value = "Need UK charger attachment.";
}
gr.cart_item.setValue(kids.sys_id);
gr.insert();
}
}
}
function nukeCart() {
var cart = getCart();
var id = cart.sys_id;
var kids = new GlideRecord('sc_cart_item');
kids.addQuery('cart', cart.sys_id);
kids.deleteMultiple();
}
function getCart() {
var cart = new GlideRecord('sc_cart');
var userid = gs.getUserID();
cart.addQuery('user', userid);
cart.query();
if (cart.next()) {
// we already have a cart all is well
}
else {
cart.initialize();
cart.user = userid;
cart.insert();
}
return cart;
}
function doOrder() {
var req = new GlideappRequestNew();
req.copyCart();
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 12:32 AM
Hi Alex,
Can you check if nukeCart() works as intended? If my understanding is correct,the cart for the 1st request is still active and it is being passed when the second request is being created? Can you check your shopping cart table as well?
Darshak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 12:17 AM
Up ?