Order Guide Scripting

dedeepya
Tera Contributor

Hi All,

We have a requirement for order guide regarding New Employee hire.

We have two items in the order guide.(Desktop,Mobile).

We need a third item(Email Account) which is not included in the order guide to be attached in the cart automatically when checked out.

Using the below script for this :

var realCart = getCart();

var cartID = realCart.sys_id;

addToCart(cartID, "6d762a9620444640217b7fa6429f7b6a",1);   //sys id of the cat item

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 getCart() {

          var cart = new GlideRecord('sc_cart');

          var userid = gs.getUserID();

          cart.addQuery('user', userid);

          cart.query();

if (cart.next()) {

                    }

          else {

                  cart.initialize();

                  cart.user = userid;

                  cart.insert();

          }

  return cart;

  }

          function doOrder() {

          var req = new GlideappRequestNew();

          req.copyCart();

  }

So we tried running this script in Background script. its working fine.

Now the question is How to call the script..

Script include - Client script - Business rule.

Please suggest.

5 REPLIES 5

manikorada
ServiceNow Employee
ServiceNow Employee

You need to keep this GlideAjax and call this from the Client Script which runs onSubmit of Order guide on first screen.


Hi Manikanta,


Thanks for the reply. I tried in the following way..


Script Include :


  1. var EmployeeUTIL = Class.create();
  2. EmployeeUTIL.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  3.   addToCart : function (cartid, cat_item, quantity) {
  4.   var gr = new GlideRecord('sc_cart_item');
  5.   gr.initialize();
  6.   gr.cart = cartid;
  7.   gr.cat_item = cat_item;
  8.   gr.quantity = quantity;
  9.   gr.insert();
  10.   },
  11.   getCart : function () {
  12.   var cart = new GlideRecord('sc_cart');
  13.   var userid = gs.getUserID();
  14.   cart.addQuery('user', userid);
  15.   cart.query();
  16.   if (cart.next()) {
  17.   }
  18.   else {
  19.   cart.initialize();
  20.   cart.user = userid;
  21.   cart.insert();
  22.   }
  23.   return cart;
  24.   },
  25.   doOrder : function () {
  26.   var req = new GlideappRequestNew();
  27.   req.copyCart();
  28.   },
  29.       type: 'EmployeeUTIL'
  30.   });


But bit confused to call this in client script.


Please help.


randrews
Tera Guru

I agree with Mani Kanta Korada   the best place to run it would be on the onsubmit script..



however if you hate ajax as much as i do.. and have a workflow that runs for the order guide <create an item with the order guides name> you could also do this as the second step of the workflow <after approval> unless this needs to be approved.



some of our order guides have standard flows that go ONLY with the workflow.. for those items we create an item with the order guides name that appears on the checkout screen with no variables... it simply has a workflow behind it.. notable among these is the new hire guide.. which assigns a task to the new hire coordinator to ensure everything is moving along and the person is able to work.


Hi Doug,



Thanks for the reply. I'll try this method if 1st won't work.




Regards,
Dedeepya