I want to increment a field value by +1 through inbound action when approval is rejected. I have a script in place but it is incrementing the value by +2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2021 05:48 AM
Hi All,
I want to increment a field value by +1 through inbound action when approval is rejected. I have a script in place but it is incrementing the value by +2.
I'm pasting my code below, anyone please help in fixing my issue.
function RejectOperation()
{
var gr2 = new GlideRecord('cmdb_hardware_product_model');
gr2.addQuery('sys_id',current.u_variable_1);
gr2.query();
if(gr2.next())
{
var assets_in_stock = gr2.u_assets_in_stock;
if(gr2.u_ci_type == 'not_contain_ci')//if assests in stock
{
//gr2.u_assets_in_stock += 1;
//gr2.u_assets_in_stock++;
gr2.u_assets_in_stock = assets_in_stock +1;
gr2.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2021 06:42 AM
I don't see anything in your code that would cause the value to increment twice; check to see if this is somehow being called more than once by your process. Add a line to your script like gs.info('RejectOperation called'); and then run the process and see if you have multiple entries in the logs occurring back to back.
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2021 07:18 AM
We have a script in record producer to reduce the number by '-1' on submit of request. Once request is submitted, it will trigger an approval. If approves rejects it should increment the value by +1, which we are setting from inbound action script as above.
Attaching the script we have in record producer, to update the field value by -1 on submit. Is this something which is causing issue?
But this works fine on submit value reduces by -1 as required.
var gr = new GlideRecord('cmdb_hardware_product_model');
gr.addQuery('sys_id',producer.product_models);
gr.query();
while(gr.next())
{
var assets_in_stock = gr.u_assets_in_stock;
if(assets_in_stock > 0)
{
current.state = '5'; // Awaiting Budget Holder
gs.eventQueue('budgetholder.approval',current,producer.thc_budget_code.u_email);
gr.u_assets_in_stock = assets_in_stock -1;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2021 09:44 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2021 09:57 AM
Where does this function "live", just on the inbound action, or in some script include perhaps? Seems like maybe it's being called again on update for some reason.
Maybe try adding gr.setWorkFlow(false); just before the update and see if that changes the behavior.
Maybe add the sys_id of current to your log statement so you can tell what record is causing the update at which time, etc.
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!