Skip to main content
Solved

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

  • May 27, 2022 7:08 AM UTC
  • 5 replies
  • 740 views
  • Translate All

priekenberg40
Varsity I
Forum|alt.badge.img+1

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"

    }



}

 

View original

5 replies

priekenberg40
Varsity I
Forum|alt.badge.img+1
  • Author
  • Varsity I
  • Jun 14, 2022 7:21 AM UTC

Can anybody give me clue?

Translate

mvolshteyn
Acumatica Moderator
Forum|alt.badge.img+3
  • Technical Account Manager in the ISV Team
  • Answer
  • Jun 15, 2022 10:49 AM UTC

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

    }



}

 

Translate

priekenberg40
Varsity I
Forum|alt.badge.img+1
  • Author
  • Varsity I
  • Jun 15, 2022 11:22 AM UTC

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

Translate

xkylewrightx
Semi-Pro I
Forum|alt.badge.img+1

That is awesome, thank you @mvolshteyn 

Translate

Forum|alt.badge.img
  • Jr Varsity II
  • Sep 24, 2024 3:54 PM UTC

Does anyone have an update for this in 24R1?

Translate