Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Record Producer creating duplicate entries.

Shidhi
Tera Contributor
var res = JSON.parse(producer.environment_selection); //multi row variable set
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
 
for (var i = 0; i < res.length; i++) {
    var row = producer.environment_selection.getRow(i);
 
    var item = cart.addItem('598e62ae1b79c254b0915287624bcbe4');     //item sysid
   
//environment selections variable set individual variables are below
 
    cart.setVariable(item, 'select_environment', row.select_the_tier);
    cart.setVariable(item, 'select_role', row.database_server);
cart.setVariable(item, 'match_type', row.database_instance);
cart.setVariable(item, 'access_level', row.access_level);
 
//user details
cart.setVariable(item, 'requested_for', producer.requested_for);
cart.setVariable(item, 'cost_center', producer.cost_center);
 
//catalog item variables
cart.setVariable(item, 'request_type', producer.request_type);
cart.setVariable(item, 'business_justification', producer.business_justification);
 
}
var rc = cart.placeOrder();
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', rc.sys_id);
ritm.query();
while (ritm.next()) {
    ritm.request = current.sys_id;
ritm.u_requested_for = producer.requested_for;
    ritm.setWorkflow(false);
    ritm.update();
}
 
var req = new GlideRecord('sc_request');
req.addQuery('number', rc.number);
req.query();
if (req.next()) {
    //gs.addInfoMessage(rc.number);
    req.deleteRecord();
}
 
 
 
 
If two sets of variables are selected two RITMs are getting created but the problem is duplicates of variables are taking instead of unique one.
 
 
Shidhi_0-1716201173041.pngShidhi_1-1716201222451.png

 

 

In the catalog item i'm using a single row variable set. Can anyone identify why it is creating duplicates.

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hi,

As an FYI the 'Cart' script include has been deprecated and customers are strongly advised to move away from it. CartJS | ServiceNow Developers

 

 

 

View solution in original post

1 REPLY 1

Kieran Anson
Kilo Patron

Hi,

As an FYI the 'Cart' script include has been deprecated and customers are strongly advised to move away from it. CartJS | ServiceNow Developers