Skip to main content
Answer

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

  • May 27, 2022
  • 5 replies
  • 611 views

priekenberg40
Varsity I
Forum|alt.badge.img

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?

Best answer by mvolshteyn

@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"

    }



}

 

5 replies

priekenberg40
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • June 14, 2022

Can anybody give me clue?


mvolshteyn
Acumatica Moderator
Forum|alt.badge.img+3
  • Technical Account Manager in the ISV Team
  • Answer
  • June 15, 2022

@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"

    }



}

 


priekenberg40
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • June 15, 2022

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


xkylewrightx
Varsity III
Forum|alt.badge.img
  • Varsity III
  • June 15, 2022

That is awesome, thank you @mvolshteyn 


Forum|alt.badge.img
  • Jr Varsity II
  • September 24, 2024

Does anyone have an update for this in 24R1?