Anyone figured out how to do 'bulk' orders in Service Portal?

Shane J
Tera Guru

I'm trying to determine the best way to do 'bulk' orders (similar to this but not the same obviously:   Enable bulk requests   ) from the Service Portal and hoping someone else has already come up with a good solution.   My use case is Security Requests, where a group of people need the exact same access BUT we need separate RITMs on the backend to get approval for individuals.

What I thought would work:

  1. Add a List style variable to the request form, in order to capture any people who need the same access
  2. Add a List field to the RITM to then take that value from the submitted form (via workflow script)
  3. Have an after Business Rule that uses a script similar to the script found here:   Re: How to clone RITM with all variables that triggers when this new List field is populated

So far my problems are as follows:

  • If that script is left unmodified, you end up creating copy RITMs until the system pukes - because the combination of the BR and script cause the copy to happen continuously.   The script needs to not copy the List variable (so there's nothing to populate it from the workflow)
  • If the script is left unmodified, you just get RITM copies for the same user.   I don't know how to modify the script to go through the values of the List field (array) to then run the copy for each user.

If you've setup something like this that works in an alternative way - I'm all ears.   Or if you know what to do with that script to fix this - again - ears.

7 REPLIES 7

larstange
Mega Sage

Hi



We have an extensive Access Management implementation, where you can order access for multiple users in the same Requested Item.


What we do is, that we split this up into seperate requests in the workflow. So the workflow checks to see if it is a single or multiple order.


If it is a multiple order, new Requests and items will be created for each user (because there will be different approvers depending on where the user is placed in the organisation) and the initial requested item will simply close.


What does the action you use to create the extra Requests look like?


larstange
Mega Sage

//Each requested application membership must be split into a seperat request




//We create a mutex, so the system only has to process one multiple access order at a time. We have seen errors happening when multuple acceses for multiple users are order in the same request - DFCT0010991




var mutex = new Mutex("###multiple_access###");


mutex.setSpinWait(10000); // time to wait between attempts, in ms - 10 seconds


mutex.setMaxSpins(1000); // maximum number of times to try




if (mutex.get()) {


        try {


                  var notes = "Bestilling af adgang til flere brugere er splittet op i følgende bestillinger:\n\n";


                  var hasAccessTxt = '';


                  var AccessUtil = new TOP_AccessUtils();



                  var catitem = current.cat_item; //Sys ID of this catalog item



                  var myUsers = new GlideRecord('sys_user');


                  myUsers.addQuery('sys_id','IN',current.variables.user_list);


                  myUsers.query();



                  while (myUsers.next()) {


                            var cart = new Cart(null, gs.getUserID()); //Create the cart as the current user


                            var item = cart.addItem(catitem);


                            cart.setVariable(item, 'type', 'single');


                            cart.setVariable(item, 'period', current.variables.period);


                            cart.setVariable(item, 'start', current.variables.start);


                            cart.setVariable(item, 'end', current.variables.end);


                            cart.setVariable(item, 'bemyndigelse', current.variables.bemyndigelse);


                            cart.setVariable(item, 'requested_for', myUsers.sys_id);


                            var rc = cart.placeOrder();


                            notes+= rc.number + " (" + myUsers.getDisplayValue() + ")\n";



                              //Set opened by, as the timer before this script will set it to "system"


                            var req = new GlideRecord('sc_request');


                            req.get(rc.sys_id);



                            req.opened_by = current.opened_by;



                            //Also transfer the cart values so we get all the options set on the cart when ordering


                            req.u_cart_values = current.request.u_cart_values;



                            req.update();


                            //set on ritm as well


                            var ritm = new GlideRecord('sc_req_item');


                            ritm.addQuery('request',rc.sys_id);


                            ritm.query();


                            while (ritm.next()) {


                                      ritm.opened_by = current.opened_by;


                                      ritm.update();


                            }


        }


        current.comments = notes;


        workflow.scratchpad.notes = notes;


}


finally {


        mutex.release();


        }


}


'mutex' is new to me, but I looked it up (thx Google).  



Is user_list a 'List' type variable?



And the way this is setup you must have to customize it per item, correct?