Page 1 of 1

Adding a new BinLocation programmatically

PostPosted: Wed Sep 05, 2018 10:22 am
by gkov3
Hi there,

What would be a recommended way to add a new BinLocation for a specific Logical Warehouse programmatically?

Thank you.

Re: Adding a new BinLocation programmatically

PostPosted: Wed Sep 05, 2018 10:24 am
by Scott.Pearce
Which Jiwa version?

Re: Adding a new BinLocation programmatically

PostPosted: Wed Sep 05, 2018 10:41 am
by gkov3
Version 7.2

Re: Adding a new BinLocation programmatically  Topic is solved

PostPosted: Wed Sep 05, 2018 10:59 am
by Scott.Pearce
Use the warehouse maintenance business logic. Code:

Code: Select all
      string IN_Physical_RecID = "ZZZZZZZZZZ0000000000"; //Or you could iterate through Manager.PhysicalWarehouseCollection, looking at property "Description" to obtain the RecID you need.
      string IN_Logical_RecID = "ZZZZZZZZZZ0000000000"; //Or you could iterate through Manager.PhysicalWarehouseCollection[IN_Physical_RecID].LogicalWarehouseCollection, looking at property "Description" to obtain the RecID you need.
      
      var physicalWarehouse = Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaWarehouses.PhysicalWarehouse>(null);
      physicalWarehouse.Read(IN_Physical_RecID);
      var logicalWarehouse = physicalWarehouse.LogicalWarehouses[IN_Logical_RecID];
      
      var newBinLocation = Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaWarehouses.BinLocation>();
      newBinLocation.Description = "My new bin location";
      
      logicalWarehouse.BinLocationCollection.Add(newBinLocation);
      
      physicalWarehouse.Save();


Remember that you will need to be referencing JiwaWarehouses.dll, and that you will also need a manager that is already set up and logged in (let me know if you need help obtaining a manager object).

Re: Adding a new BinLocation programmatically

PostPosted: Wed Sep 05, 2018 11:01 am
by Scott.Pearce
You could also look at Manager.CurrentLogicalWarehouse to obtain the RecID of the current warehouse if that's what you need.

Re: Adding a new BinLocation programmatically

PostPosted: Wed Sep 05, 2018 11:05 am
by gkov3
Thank you.

I was trying to create and configure a collection "BinLocationCollection" via CollectionFactory.CreateCollection<JiwaFinancials.Jiwa.JiwaWarehouses.BinLocationCollection> but hit a wall as it didn't have right interfaces.

Re: Adding a new BinLocation programmatically

PostPosted: Wed Sep 05, 2018 11:10 am
by Scott.Pearce
Yeah, a bin location exists in a logical warehouse, and a logical warehouse exists in a physical warehouse - therefore it is necessary to read the parental objects to give context to the child objects.

When saving, a bin location would look to its owner logical warehouse for the IN_Logical_RecID value to save into the bin location table in the database.

Re: Adding a new BinLocation programmatically

PostPosted: Wed Sep 05, 2018 12:14 pm
by gkov3
Thanks again, it is working now,

Got an unexpected situation during a demo "as always happens" where inventory had an item with a specific bin description that wasn't listed in the [IN_BinLocationLookup] so the following method
JiwaStockTake.LineDetail.BinLocation.ReadRecordFromDescription was failing. Catching the exception, creating a bin on a fly and calling the failing method again fixed the issue.

Re: Adding a new BinLocation programmatically

PostPosted: Wed Sep 05, 2018 12:26 pm
by Scott.Pearce
Bin locations were changed at some point relatively recently. They used to be a little loose and allowed users to type in ad-hoc bin location descriptions as stock was moved around. That has since has been tightened up so that now bin locations must be properly defined, and then selected by the user.

If you can give me some specifics regarding the problem you came across I can log a bug/fix our demo data so others don't get caught out by the same thing.

Re: Adding a new BinLocation programmatically

PostPosted: Wed Sep 05, 2018 12:33 pm
by gkov3
Sure, I will try to compile exact steps. I thought that was normal haven't tried to see how Jiwa handles it.