Change the sales order warehouse on CreateEnd  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Change the sales order warehouse on CreateEnd

Postby DannyC » Tue Jan 11, 2022 12:47 pm

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      
User avatar
DannyC
Senpai
Senpai
 
Posts: 638
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Change the sales order warehouse on CreateEnd

Postby SBarnes » Tue Jan 11, 2022 1:01 pm

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1621
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 176

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

Postby Mike.Sheen » Tue Jan 11, 2022 1:12 pm

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);
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Change the sales order warehouse on CreateEnd

Postby DannyC » Tue Jan 11, 2022 1:22 pm

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! ;)
User avatar
DannyC
Senpai
Senpai
 
Posts: 638
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Change the sales order warehouse on CreateEnd

Postby Mike.Sheen » Tue Jan 11, 2022 2:11 pm

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.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 5 guests