Solved

How to link production order to sales order line by Rest-API


Userlevel 2
Badge

I’ve created a sales order with one line and a production order by Rest-API. I would like to link these orders by API. PUTing "SOLineNbr", "SOOrderNbr", "SOOrderType" into production order object doesn’t work. These fields stay null. The other way i get an error: "An error occurred during processing of the field AMProdOrdID: A numbering sequence for the order type is not configured.." Which is wrong.
Any ideas?

icon

Best answer by mvolshteyn 15 June 2022, 12:49

View original

4 replies

Userlevel 2
Badge

Can anybody give me clue?

Userlevel 5
Badge +3

@priekenberg40 , this cannot be done that straightforward.

Filling of the "SOLineNbr", "SOOrderNbr", "SOOrderType" fields should be the result of the LinkProductionOrders method. Filling these fields through API does not trigger this method

This might be addressed in  future versions, but now you should implement all this logic yourself.

You can use the following approach:

  1. Extend AMProdItem dac by adding unbound copies of the "SOLineNbr", "SOOrderNbr", "SOOrderType" fields marked as [PXUIField(DisplayName =<FieldName>, Enabled = true, Visible = false)]
  2. Add these fields to the .aspx page (they are not visible, so won’t appear in UI)

    See the attached customization which does (1), (2)
  3. Extend the MANUFACTURING endpoint and add these fields there 
    (see MFGEndpointExtensionforLinkSalesOrder.png)
  4. Write the logic which calls the LinkProductionOrders method when these fields are filled through API, like this:
public class AMProdMaintAPIExtension : PXGraphExtension<ProdMaint>
    {
        public virtual void AMProdItem_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
        {
            var row = (AMProdItem)e.Row;
            var oldRow = (AMProdItem)e.OldRow;
            if (row == null || !Base.IsContractBasedAPI)
            {
                return;
            }
            AMProdItemAPIExtension rowExtAPI = row.GetExtension<AMProdItemAPIExtension>();
            if (rowExtAPI == null)
            {
                return;
            }

                if (!cache.ObjectsEqual<AMProdItemAPIExtension.usrapiordLineRef, AMProdItemAPIExtension.usrApiordNbr,
                AMProdItemAPIExtension.usrApiordTypeRef>(oldRow, row))
            {
                var soLine = (SOLine)PXSelect<SOLine,
                        Where<SOLine.orderType, Equal<Required<SOLine.orderType>>,
                            And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
                            And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>
                    >.SelectWindowed(Base, 0, 1, rowExtAPI.UsrApiOrdTypeRef, rowExtAPI.UsrApiOrdNbr,
                    rowExtAPI.UsrapiordLineRef);
                if (soLine == null)
                {
                    return;
                }
                PXGraph.CreateInstance<SOOrderEntry>()?.
                    GetExtension<SOOrderEntryAMExtension>()?.LinkProductionOrders(Base, soLine,
                    row);
            }
        }

    }

 

then PUT request with these new fileds filled will link the specified sales order to the production order created:

 {

    /*"ProductionNbr": {

        "value": "<NEW>"

    },*/

    "OrderType": {

        "value": "RO"

    },

    "InventoryID": {

        "value": "MGBASE"

    },

    "note": "",

    "Warehouse": {

        "value": "WHOLESALE"

    },

    "QtytoProduce": {

        "value": "2"

    },

    "SOLineNbrAPI": {

        "value": "1"

    },

      "SOOrderNbrAPI": {

        "value": "SO006539"

    },

      "SOOrderTypeAPI": {

        "value": "SO"

    }



}

 

Userlevel 2
Badge

@mvolshteyn Great idea! Haven’t thought of such an approach up to now. I’ll try this the next days...

Userlevel 5
Badge

That is awesome, thank you @mvolshteyn 

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 — 2024  Acumatica, Inc. All rights reserved