E: Clean stock

This JBS Example clean complete stock. You can save this in a source file in project folder and can call from different places

 

#jbs
#include "issuetools.jbs"; // Load from this file
cleanStock(String Warehouse,String ItemCode); // execute the function

 

Warehouse, which you want to clean (mandatory)

Item, which you want to clean. If empty, then all items

Note: Beas delete Beas-Reservation, but can't delete SAP Reservations. If a SAP Reservation is existing, the system can't create an issue for the item and return an error message.

 

Example:

 

#jbs
#include "issuetools.jbs";
cleanStock("01","RM_S_N");

 

 

jbscript-logo-small

 

// Clean up Stock for warehouse or/and itemcode
// 3.6.2020 M.Heigl
// ***********************************************

// Declare as local instance
let cleanStock=function cleanStock(e_WhsCode,e_ItemCode ) {

 
if (e_WhsCode == "" ) {
   alert("deleteStock(): Please define warehouse");
   return -1;
}
 
 

// ItemCode is empty: Load stock from all items from this warehose
// Note: The system delete reservation by SQL statement. Not the best solution, but current no other function available
if (e_ItemCode != "" ) {
   let stock=bsl.get ("WareHouseStock(:e_WhsCode)?$filter=ItemCode = :e_ItemCode and OnHand > 0");
   SQLStatement.execute("delete from \"BEAS_RESERVATION_LINE\" where \"ItemCode\"=:e_ItemCode and \"WhsCode\"=:e_WhsCode");
   }

// Item is defined. Load only for this item
else {
   let stock=bsl.get ("WareHouseStock(:e_WhsCode)?$filter=OnHand > 0");
   SQLStatement.execute("delete from \"BEAS_RESERVATION_LINE\" where \"ItemCode\"=:e_ItemCode ");
   }
if (stock.rowcount() == 0) return 1;
 
// Create JSON as String (not object)

// alternative it's possible to create a JSON Object.

// Note: You don't need to group the items for Batch/Serial numbers. The system will do this automatically.
let ls_transaction="";
for (let ll_stock=1;ll_stock <= stock.rowcount();ll_stock++){
   stock.setrow(ll_stock);
   if (ll_stock > 1)      ls_transaction+=",";
   
   ls_transaction += '{"ItemCode":"'+stock.itemcode+'","Quantity":'+stock.onhand.toString()+',"Whscode":"'+e_WhsCode+'",'+
         '"SysNumber":'+stock.sysnumber+',"DistNumber":"'+stock.batch+'","BinCode":"'+stock.bincode+'","IVersionId":"'+stock.iversionid+'"}';
   }
 
ls_transaction='{"DocumentLines":['+ls_transaction+']}';
 
// Execute BSL Post command
// Second post parameter can be a json string or a variable
let b=bsl.post("Issue",ls_transaction);
if (b.returnCode) != 0 
  alert(b.returnMessage+"  "+b.returnResult);
return 1;
};
 
 
help-hinweis Example Notes