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

This script is running in a Record Producer.

Record producers run to task-based records for example incident, change, demand etc. It doesn't create request and requested items. Typically, it creates a record in the target table [task based] only.

If you don't have any specific configuration in place then this script shouldn't work as current object represents the target table which is not request table in the record producer's case. The method addItemToExistingRequest("request sysid", <cat item id>, 1) requires to have a Request sys id as a first paramter instead we are passing in the target records sys_id. 

Can you expand and give some more details about the record producer so that we can help you better. 

Regards,
Muhammad

Record producer is over de sc_request table so a Request is created automatically. Debugging you can see that a request sys_id is sent to addItem function. What you obtain debugging is that reqHelper object is not created after new instruction.

My goal is to generate automatically multiple request Items depending on record producer multi-row variable set heterogeneus values. Request will group diferent rows of the variable set in a unique homogeneus RITM.

hanaphouse
Giga Guru

Have you tried making the quantity as a string - "1"?

Is this running on a scoped app or a global app? Scoped app does not support GlideappCalculationHelper

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

Docs: https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/GlideappCalcHelperAPI

Tested. Not working