add item to existing request

SME
Giga Guru

Hi Everyone,

Have a question, trying to use GlideappCalculationHelper         to add 2 request item to an existing request but my script doesnot seems to work... It is not creating additional items. Can anyone help on this or give anyother way of doing it. I used this link https://community.servicenow.com/thread/184740     .Below is my script :-

function onAfter(current, previous) {

  if(current.variables.bundle == 'corporate_standard') {

  for(var i=0; i<2; i++) {

  // add item to current request

  gs.log(current.request);

  var reqHelper = new GlideappCalculationHelper();

  reqHelper.addItemToExistingRequest(current.request, '039c516237b1300054b6a3549dbe5dfc', 1); // 1 is the qty

  reqHelper.rebalanceRequest(current.request);

  gs.log("hi");

  // update/add values to variables on item

  var grReqItem = new GlideRecord('sc_req_item');

  grReqItem.addQuery('request', current.request);

  grReqItem.addQuery('cat_item','039c516237b1300054b6a3549dbe5dfc');

  grReqItem.query();

  if(grReqItem.next()) {

  grReqItem.variables.u_test = 'true';

  grReqItem.parent = current.sys_id;

  grReqItem.update();

  }

  }

  }

}

1 ACCEPTED SOLUTION

SME
Giga Guru

I finally found the problem...This script should be written in after business rule on sc_request.   I was writing it on sc_req_item thats why it was not working.



Thanks.


View solution in original post

4 REPLIES 4

SME
Giga Guru

I finally found the problem...This script should be written in after business rule on sc_request.   I was writing it on sc_req_item thats why it was not working.



Thanks.


Hi Mansi



I think I can use some of your solution above. But not quite.



Could you please take at look at this: Add item to an existing request



..and see if there you have more hints for it.



Thanks in advance


Soren


FinToy
Mega Expert

Can you please advice how to use this in Requested Item workflow? Based on user selections, I need to add certain items to the Request and this looks promising. Thanks!


mak1A4
Tera Guru

If you're looking for a way to achieve this with the CartJS API have a look at this Article:

https://community.servicenow.com/community?id=community_article&sys_id=0585e0a71bc98554cdd555fa234bc...