i tried to run a business rule to check availabilty in the stockroom but it is not working

chercm
Mega Sage

Hi 

 

i need some help . the below is not working for me 

 

// Check items and quantities in variables
var items = current.variables.item_requested; // Assuming "item" is the variable name for items
var req_quantity = current.variables.quantity; // Assuming "quantity" is the variable name for quantities

var consumableGR = new GlideRecord('alm_asset');
consumableGR.addQuery('install_status', 6);
consumableGR.addQuery('stockroom', current.u_stockroom);
consumableGR.addQuery('sys_id', items);
consumableGR.query();
gs.info('Number of records: ' + consumableGR.getRowCount());
 
// Check consumable availability for each item
if (consumableGR.next()) {
var availableQuantity = consumableGR.getValue('quantity');
try {
var quantity = availableQuantity - req_quantity;
if (quantity >= 0) {
current.setAbortAction(false); // Adjusted to false if quantity is sufficient
return;
} else {
gs.addErrorMessage('Insufficient consumable items for item: ' + items + ' in the new Assignment Group. Assignment Group cannot be changed.');
current.setAbortAction(true);
return;
}
} catch (ex) {
gs.addErrorMessage('Unexpected Error: ' + ex.message);
current.setAbortAction(true);
return;
}
}
})(current, previous);
 
chercm_0-1707228322935.png

 

 
 
9 REPLIES 9

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Is this a list of single item?

var items = current.variables.item_requested; // Assuming "item" is the variable name for items

-Anurag

@Anurag Tripathi i am looking for a single item that i am looking for 

 

chercm_0-1707256490040.png

@Ankur Bawiskar 

 

i did a gs.info but i am not getting any result on the logs

 

var consumableGR = new GlideRecord('alm_asset');
consumableGR.addQuery('install_status', 6);
consumableGR.addQuery('stockroom', current.u_stockroom);
consumableGR.addQuery('sys_id', items);
consumableGR.query();
gs.info('Number of records: ' + consumableGR.getRowCount());

Log current.u_stockroom & items, one of this is failing.

Print these values and show here what you get.

-Anurag

@Anurag Tripathi  @Ankur Bawiskar i used this 

 

// Check items and quantities in variables
var items = current.variables.item_requested; // Assuming "item" is the variable name for items
var req_quantity = current.variables.quantity; // Assuming "quantity" is the variable name for quantities
gs.info("Items requested: " + items);
gs.info("Requested quantity: " + req_quantity);
 
i do not see anything in the logs
 
chercm_0-1707312053092.png