Why does placeOrder() take so much time to create Request?

luisesparza
Kilo Contributor

Hi All!

I have a requirement to create several Requested Items in a Request based on a list of elements specified by the user in a catalog item as part of a scopped application. What I do is to obtain the list of elements entered by the user and create a RITM per element as I iterate through them. For this, I use the Cart API. So far, the script creates the REQ and RITMs correctly but it takes too much time (about 1 minute) to generate the records.

I have tried a little debugging by printing messages (with "gs.info(...)" ) and I have detected that the moment when the execution turns slow is when I call the placeOrder() method. Does anyone know why it takes so much time in this part, or have any suggestions to avoid this wait time?

Below I paste the Script Include I wrote and the log information printed in the logs.

var AccsRequest_CreateRITMs = Class.create();

AccsRequest_CreateRITMs.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

  createRITMs: function() {

  var t1 = new Date();

  gs.info("#1 Entered server function > " + t1);

  // Receive data from client

  var usr_sysid = this.getParameter('sysparm_usr');

  var roles_str = this.getParameter('sysparm_approles');

  var roles_array = roles_str.split(" // "); // Separate string into an array.

  var t2 = new Date();

  gs.info("#2 Splitted roles string into array > " + t2);

  var cart = new global.Cart();

  var t3 = new Date();

  gs.info("#3 Created Cart class object > " + t3);

  // Change 'Requested for'

  var cartGR = cart.getCart();

  cartGR.requested_for = usr_sysid;

  cartGR.update();

  var t4 = new Date();

  gs.info("#4 Changed [Requested For] value > " + t4);

  // Iterate

  for(var i = 0; i < roles_array.length; i++) {

  var item = cart.addItem('7fc1df6bdba7220004effcdfbf9619b7');

  cart.setVariable(item, 'acctp_user', usr_sysid);

  cart.setVariable(item, 'acctp_allroles', roles_array[i].toString());

  cart.setVariable(item, 'requested_for', usr_sysid);

  var t5 = new Date();

  gs.info("#5 Added RITM" + (i + 1)   + " to cart > " + t5);

  }

  var t6 = new Date();

  gs.info("#6 Ended order preparation > " + t6);

  var rc = cart.placeOrder();

  var t7 = new Date();

  gs.info("#7 Created order > " + t7);

  gs.addInfoMessage("Created order: " + rc.number);

  },

      type: 'AccsRequest_CreateRITMs'

});

find_real_file.png

I hope you can give me a hand, thanks in advance!

1 ACCEPTED SOLUTION

larstange
Mega Sage

Hi



How many items to you add to the cart, and is there a workflow running for each item?



If the workflow does some sort of processing, then submitting the cart will wait for this processing to be finished.



You can add a 1 second timer as the first activity in the workflow to make it more responsive


View solution in original post

2 REPLIES 2

larstange
Mega Sage

Hi



How many items to you add to the cart, and is there a workflow running for each item?



If the workflow does some sort of processing, then submitting the cart will wait for this processing to be finished.



You can add a 1 second timer as the first activity in the workflow to make it more responsive


Hi Lars!



The number of items I add to the cart depends on how many items are chosen by the user (generally it is about 3 - 5 items). And yes, there is a workflow that runs for added item. I tried adding the timer as the first activity, and the solution seems to be working: the wait time so far goes down to just a few seconds. Thanks a lot!