Question

PO Link in code

  • 26 October 2022
  • 5 replies
  • 73 views

I can successfully create a SO and create a PO from the SO in code. I can receipt the PO on the screen and then ship the SO on the screen. It all works 100%. 

The PO Link on the SO is enabled but when I click on it the link is empty. How can I build the link in code?


5 replies

Userlevel 5
Badge

Hi @wikusvorster42 

When you are linking SOs to POs you need to do it via Supply. This is an excerpt of how you link both:


...
var soEntryPOLinkDialog = soEntry.GetExtension<POLinkDialog>();
var soEntryPurchaseToSOLinkDialog = soEntry.GetExtension<PurchaseToSOLinkDialog>();
...


foreach (SupplyPOLine po3 in soEntryPOLinkDialog.
SupplyPOLines.
Select().
RowCast<SupplyPOLine>().
Where(w => w.OrderNbr == soLineLnk.POOrderNbrTo &&
w.OrderType == soLineLnk.POOrderTypeTo))
{
if(!(po3.Selected ?? false))
{
poLinkAttempt = true;
soEntryPOLinkDialog.SupplyPOLines.Current = po3;
po3.Selected = true;
soEntryPOLinkDialog.SupplyPOLines.Update(po3);

// This is who does the linking work
soEntryPurchaseToSOLinkDialog.LinkPOSupply(soEntry.Transactions.Current);
}
}

...

Of course you have to validate if SOLines are POCreate enabled previous to this.

 

Hope this can help you in your journey.

Thank for the reply, Leo.

At what stage do I do the code you sent. After the PO was created?

I did this but I can’t get the POLink to work:

public void AddLinkPOSupplyEx(POLine line, SOLine soLine)
        {
            var soEntryPOLinkDialog = Base.GetExtension<POLinkDialog>();
            var soEntryPurchaseToSOLinkDialog = Base.GetExtension<PurchaseToSOLinkDialog>();

            var supply = new SupplyPOLine
            {
                OrderType = line.OrderType,
                OrderNbr = line.OrderNbr,
                LineNbr = line.LineNbr,
                InventoryID = line.InventoryID,
                SiteID = line.SiteID,
                BaseOrderQty = line.BaseOrderQty,
                PlanID = line.PlanID
            };
            supply = soEntryPOLinkDialog.SupplyPOLines.Insert(supply);
            soEntryPOLinkDialog.SupplyPOLines.Current = supply;
            
            soEntryPurchaseToSOLinkDialog.LinkPOSupply(soLine);

        }

Userlevel 5
Badge

Hi @wikusvorster42 

To make the link work both the SO and the PO must exist. You could automatically link SOs after a PO has been created (Ex. RowPersisted event) or in a custom process or even adding a button in the PO screen to link any SO related to the purchased items.

The code provided works better on a processing context and shows how to deal with the linking functions in the Sales Order side of things. 

Acumatica Linking process is done by the function

soEntryPurchaseToSOLinkDialog.LinkPOSupply(<SOLine>);

As you can see this works in the context of the Sales Order Screen. You have to work with the provided Acumatica structures.

When you see things like:

po3.Selected = true;
soEntryPOLinkDialog.SupplyPOLines.Update(po3);

Is more like the user is clicking the checkbox in the UI. Several events are triggered. And you want Acumatica do the same thing but in an automated way.

In summary, you have to load the Sales Order and then go to the specific structure and automate the selection of the linking, similar to the code provided, and according to your requirements and needs.

 Hi Leo,

When I execute the soEntryPOLinkDialog.SupplyPOLines.Select() and step into the code, it doesn't find any data. I do this after the PO was created from the SO. I attached my code.

 

Hi Leo,

I managed to get past the above issue but there is still no record(s) in the PO Link. I changed the code as follows:

SOOrderEntry iegraph = PXGraph.CreateInstance<SOOrderEntry>();
iegraph.Document.Current = iegraph.Document.Search<SOOrder.orderNbr>(soorder.OrderNbr, soorder.OrderType);
foreach (SOLine orderLine in orderLines)
{
iegraph.Transactions.Current = orderLine;
var extgraph = iegraph.GetExtension<SOOrderEntry_Extension>();
extgraph.AddLinkPOSupply(orderLine, PONumber);
}

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2022  Acumatica, Inc. All rights reserved