Page 1 of 1

Change the sales order warehouse on CreateEnd

PostPosted: Tue Jan 11, 2022 12:47 pm
by DannyC
I'm writing a plugin to change a sales order LogicalWarehosueResidingIn based on a debtor custom field. The debtor custom field denotes which warehouse they require their sales order placed in. The value saved to the database is the INLogicalID.
Piece of cake to get the INLogicalID, but if it's different to the current warehouse then I want to change the sales order warehouse to the one specified from the debtor custom field.

Have tried 3 different ways to change the sales order warehouse but none are working. Need some tips!

Version 7.2.1 SR8. C#.

Code: Select all
salesOrder.LogicalWarehouseResidingIn.ReadRecord(DefaultWarehouseID);    //doesn't work
salesOrder.LogicalWarehouseResidingIn.IN_LogicalID = DefaultWarehouseID;    //doesn't work
JiwaFinancials.Jiwa.JiwaApplication.Entities.LogicalWarehouse logicalWH = salesOrder.Manager.EntityFactory.CreateEntity<JiwaFinancials.Jiwa.JiwaApplication.Entities.LogicalWarehouse>();
logicalWH.ReadRecord(DefaultWarehouseID);
salesOrder.LogicalWarehouseResidingIn = logicalWH;  //doesn't work      

Re: Change the sales order warehouse on CreateEnd

PostPosted: Tue Jan 11, 2022 1:01 pm
by SBarnes
You usually set the warehouse through a call to createnew on the sales order, I suspect you would need to use the setup before handler on the form and take over.

Take a look at the code in the NewRecord function on the actual sales order form to see what you need to do.

Re: Change the sales order warehouse on CreateEnd  Topic is solved

PostPosted: Tue Jan 11, 2022 1:12 pm
by Mike.Sheen
LogicalWarehouseResidingIn isn't the property you want to be interacting with.

LogicalWarehouseResidingIn is a property to satisfy the JiwaApplication.IJiwaWarehouseFiltering interface - it's purely for making sure when you read next / previous and search and so on that it only includes orders in that warehouse.

What you want to do is read BOTH the LogicalWarehouseResidingIn AND the Warehouse properties. You don't have to read LogicalWarehouseResidingIn, but if this is in a UI context the user might be confused if they save their order, and then can't see it in a search or if they read previous then next and it's not there anymore.

The Warehouse property isn't the usual Entity type that LogicalWarehouseResidingIn is either - it needs to be one of the warehouses hanging down off the PhysicalWarehouseCollection of the manager - luckily we have a helper function in there to retrieve the logical warehouse for you from a given Logical ID.

This should work:

Code: Select all
salesOrder.LogicalWarehouseResidingIn.ReadRecord(DefaultWarehouseID);
salesOrder.Warehouse = Manager.PhysicalWarehouseCollection.FindLogicalWarehouse(DefaultWarehouseID);

Re: Change the sales order warehouse on CreateEnd

PostPosted: Tue Jan 11, 2022 1:22 pm
by DannyC
What you want to do is read BOTH the LogicalWarehouseResidingIn AND the Warehouse properties


Ah ha!! Awesome - just what I was after.

Really appreciate the fast reply Mike. Saved the day yet again. Just wish I posted that question a couple of hours ago! ;)

Re: Change the sales order warehouse on CreateEnd

PostPosted: Tue Jan 11, 2022 2:11 pm
by Mike.Sheen
DannyC wrote:Just wish I posted that question a couple of hours ago! ;)


When I spend time struggling with something, I'm more likely to retain the answer for longer.

My knowledge is acquired through thousands of hours of pain.