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.

how to filter based on selected stock room ?

chercm
Mega Sage

Stockroom -> alm_stockroom

Consumable -> alm_consumable

 

i tried to use this qualifier on the consumable but i kept getting everything not the one specified to the selected stock room 

 

javascript: "install_status=6^stockroom=" + current.getValue('stockroom');
3 ACCEPTED SOLUTIONS

Hi @chercm ,

 

It should be u_stockroom. Replace with u_ for stockroom n check.

 

Thanks,

Danish

View solution in original post

@chercm It is a custom field change your reference qualifier to this.

 

javascript : "install_status=6^stockroom=" + current.u_stockroom;

 

Thanks,
Anvesh

View solution in original post

Hi @chercm 

What I understood is you are expecting to deduct the stock when a Catalog Task is closed.

 

Try creating a business rule like the one below.

 

Name: Deduct asset quantity from stock

Table: sc_task

Advanced: True

 

When to Run Section:

When: After

Insert: True

Update: True

 

Conditions:

Asset :: is Not Empty

Stock Room :: is Not Empty

State :: Changes to :: Closed Complete

 

 

Advanced Section:

 

Script:

 

(function executeRule(current, previous){

var almGr = new GlideRecord('alm_asset');

almGr.addQuery('sys_id', current.u_reference_1);

almGr.query();

if(almGr.next()){

   var quantity= almGr.getValue('quantity');

   var req_quantity= current.request_item.quantity;

   try{

      quantity = quantity - req_quantity;

      if(quantity >= 0){

         almGr.setValue('quantity', quantity);

         almGr.update();

      } else{

         gs.addErrorMessage('Available quantity is less than the requested quantity, unable to update the stock.');

      }

   }catch(ex){

      gs.addErrorMessage('Unexpected Error:' + ex.message);

   }

}

 

}

 

)(current, previous)

 

 

Please mark my answer helpful and accept as solution if it helped you 👍

Thanks,
Anvesh

View solution in original post

32 REPLIES 32

AnveshKumar M
Tera Sage
Tera Sage

Hi @chercm 

Have you tried this

javascript : "install_status=6^stockroom=" + current.stockroom;

 

In place of : use :

Thanks,
Anvesh

do you mean the command should be this : 

 

Screenshot 2023-10-06 at 9.35.55 AM.png

chercm
Mega Sage

@AnveshKumar M i used the command , it did filter the instock for the consumable table but not on the Stockroom that was selected

 

Screenshot 2023-10-06 at 9.38.13 AM.png

@chercm  I see you are using Capital S in Stockroom, try with all small case letters 

stockroom=" + current.stockroom

 

 

If it didn't work, please check the field name of Stockroom once in your table where you are using this reference qualifier.

Thanks,
Anvesh