GlideappCalculationHelper API is not working on a Record Producer

AdriaM
Mega Sage

I'm trying to generate multiple RITM with a Record Producer and GlideappCalculationHelper API.

Script is not working. Nobody knows why?

var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.sys_id.getValue(), <cat item id>, 1); // 1 is the qty
reqHelper.rebalanceRequest(current.sys_id.getValue());

1 ACCEPTED SOLUTION

AdriaM
Mega Sage

Best Way to solve this is use Service Catalog Script API to create both Request and RITM needed and then abort record producer to not generate a new boid request item.

Here is the code:

// cat_item sys_id
var CN = '43d255771b812010c01fff37dc4bcbcd';

// Create new chart
var cart = new sn_sc.CartJS();

// add item to char
var item =
{
'sysparm_id': CN,
'sysparm_quantity': '1',
'variables':{
<item variables>
}};
var cartDetails = cart.addToCart(item);

// Checkout Chart
var checkoutInfo = cart.checkoutCart();

// Redirect record producer to new request item
producer.redirect='sc_request.do?sys_id=' + checkoutInfo.request_id;
producer.portal_redirect='sp?id=sc_request&is_new_order=true&table=sc_request&sys_id=' + checkoutInfo.request_id;

// Abort new boid request creation
current.setAbortAction(true);

View solution in original post

11 REPLIES 11

MrMuhammad
Giga Sage

Please try this

var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.getValue("sys_id"), <cat item id>, 1); // 1 is the qty
reqHelper.rebalanceRequest(current.getValue("sys_id"));

Note - GlideappCalculationHelper API doesn't work in the scoped app.

Regards,
Muhammad

Tested. Not Working.

Are you testing this in the global scope or custom scope? The API is not supported in the scoped application. 

Regards,
Muhammad

Where are you running this script? Business rule on request table?

Regards,
Muhammad