xDJR1875
xDJR1875

Reputation: 280

How can I insert a note into a sales order notes while inserting a sales order using the api?

I am using Acumatica 4.2 and inserting Sales Orders through the api from another system. The request has come up to add notes to the sales order and I am not seeing anything useful on how to go about doing this. thanks in advance. Here is my code for inserting the SalesOrder using the Acumatica WebAPI. It functions very well.

On the Sales Order Screen there is also a Notes indicator on the upper right where notes can be added to the sales order. How would I go about adding a note by using the acumatica web api? or do I simply use the returned SONumber and insert the note using the SONumber as a reference. I have not had to deal with notes before.

    try
    {
        cmds.AddRange(
            new SO301000_509.Command[]
        {
            so301000.Actions.Insert,
                    new SO301000_509.Value { Value = "SO", LinkedCommand = so301000.OrderSummary.OrderType },
                    new SO301000_509.Value { Value = "='new'", LinkedCommand = so301000.OrderSummary.OrderNbr },
                    new SO301000_509.Value { Value = dealerOrder.accountCode, LinkedCommand = so301000.OrderSummary.Customer },
                    //new SO301000_509.Value { Value = ((DateTime)dealerOrder.orderDateTime).ToShortDateString(), LinkedCommand = so301000.OrderSummary.Date },
                    new SO301000_509.Value { Value = (dealerOrder.orderDateTime), LinkedCommand = so301000.OrderSummary.Date },
                    new SO301000_509.Value { Value = "Hubsoft Order Nbr: " + dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.Description },
                    new SO301000_509.Value { Value = dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.CustomerRef },
                    new SO301000_509.Value { Value = "HS-" + dealerOrder.purchaseOrderNumber, LinkedCommand = so301000.OrderSummary.CustomerOrder },
                    //new SO301000_509.Value { Value = dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.ControlTotal },
        }
        );
        //create the sales order lines in loop
        for (var idx = 0; idx < SalesOrderLine.Length; idx++)
        {
            cmds.AddRange(
                new SO301000_509.Command[]
            {
                so301000.DocumentDetails.ServiceCommands.NewRow,
                    //simple line adding
                    so301000.DocumentDetails.ServiceCommands.NewRow,
                    new SO301000_509.Value { Value = SalesOrderLine[idx].inventoryCD, LinkedCommand = so301000.DocumentDetails.InventoryID },
                    new SO301000_509.Value { Value = SalesOrderLine[idx].UOM, LinkedCommand = so301000.DocumentDetails.UOM },
                    new SO301000_509.Value { Value = SalesOrderLine[idx].Qty, LinkedCommand = so301000.DocumentDetails.Quantity },
                    new SO301000_509.Value { Value = "MAIN", LinkedCommand = so301000.DocumentDetails.Warehouse},                        
                    new SO301000_509.Value { Value = SalesOrderLine[idx].UnitPrice, LinkedCommand = so301000.DocumentDetails.UnitPrice, Commit = true },
            }
            );
        }
        cmds.Add(so301000.Actions.Save);                                                //save all
        cmds.Add(so301000.OrderSummary.OrderNbr);                                       //return Order #

        SO301000_509.Content[] SO301000Content = context.Submit(cmds.ToArray());            //submit
        PXTrace.WriteInformation(SO301000Content[0].OrderSummary.OrderNbr.Value);
        acumaticaSONbr = SO301000Content[0].OrderSummary.OrderNbr.Value;
    }
    catch (Exception ex)
    {
        PXTrace.WriteError("Error adding Sales Order - " + ex.Message);
    }
    return acumaticaSONbr;

Upvotes: 0

Views: 496

Answers (2)

xDJR1875
xDJR1875

Reputation: 280

Another way of doing this is within the first insert of the Sales Order itself. The example posted by acumember required a 2nd call to the API. Since we are inserting many Sales Orders at a time, we want to limit our calls. So the following also works and requires only the one call.

thanks

        try
        {
            cmds.AddRange(
                new SO301000_509.Command[]
            {
                so301000.Actions.Insert,
                        new SO301000_509.Value { Value = "SO", LinkedCommand = so301000.OrderSummary.OrderType },
                        new SO301000_509.Value { Value = "='new'", LinkedCommand = so301000.OrderSummary.OrderNbr },
                        new SO301000_509.Value { Value = dealerOrder.accountCode, LinkedCommand = so301000.OrderSummary.Customer },
                        new SO301000_509.Value { Value = (dealerOrder.orderDateTime), LinkedCommand = so301000.OrderSummary.Date },
                        new SO301000_509.Value { Value = "Hubsoft Order Nbr: " + dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.Description },
                        new SO301000_509.Value { Value = dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.CustomerRef },
                        new SO301000_509.Value { Value = "HS-" + dealerOrder.purchaseOrderNumber, LinkedCommand = so301000.OrderSummary.CustomerOrder },

                        **new SO301000_509.Value { Value = dealerOrder.notes, LinkedCommand = so301000.OrderSummary.NoteText},**

                        new SO301000_509.Value { Value = "1", LinkedCommand = so301000.ShippingSettingsShipToInfo.OverrideAddress },
                        new SO301000_509.Value { Value = shipStreet1, LinkedCommand = so301000.ShippingSettingsShipToInfo.AddressLine1 },
                        new SO301000_509.Value { Value = shipStreet2, LinkedCommand = so301000.ShippingSettingsShipToInfo.AddressLine2 },
                        new SO301000_509.Value { Value = shipCity, LinkedCommand = so301000.ShippingSettingsShipToInfo.City },
                        new SO301000_509.Value { Value = shipState, LinkedCommand = so301000.ShippingSettingsShipToInfo.State },
                        new SO301000_509.Value { Value = shipCountry, LinkedCommand = so301000.ShippingSettingsShipToInfo.Country },
                        new SO301000_509.Value { Value = shipPostal, LinkedCommand = so301000.ShippingSettingsShipToInfo.PostalCode },
            }
            );
            //create the sales order lines in loop
            for (var idx = 0; idx < SalesOrderLine.Length; idx++)
            {
                cmds.AddRange(
                    new SO301000_509.Command[]
                {
                    so301000.DocumentDetails.ServiceCommands.NewRow,
                        //simple line adding
                        so301000.DocumentDetails.ServiceCommands.NewRow,
                        new SO301000_509.Value { Value = SalesOrderLine[idx].inventoryCD, LinkedCommand = so301000.DocumentDetails.InventoryID },
                        new SO301000_509.Value { Value = SalesOrderLine[idx].UOM, LinkedCommand = so301000.DocumentDetails.UOM },
                        new SO301000_509.Value { Value = SalesOrderLine[idx].Qty, LinkedCommand = so301000.DocumentDetails.Quantity },
                        new SO301000_509.Value { Value = "MAIN", LinkedCommand = so301000.DocumentDetails.Warehouse},                        
                        new SO301000_509.Value { Value = SalesOrderLine[idx].UnitPrice, LinkedCommand = so301000.DocumentDetails.UnitPrice, Commit = true },
                }
                );
            }
            cmds.Add(so301000.Actions.Save);                                                    //save all
            cmds.Add(so301000.OrderSummary.OrderNbr);                                           //return Order #

Upvotes: 0

srodionov
srodionov

Reputation: 205

        Content SO301000 = context.GetSchema();
        context.Clear();
        Content[] result = context.Submit(
            new Command[]{
                new Value { Value = "000586", LinkedCommand = SO301000.OrderSummary.OrderNbr, Commit = true },
                new Value { Value = "NoteText", LinkedCommand = SO301000.OrderSummary.NoteText, Commit = true },
                SO301000.Actions.Save
            }
        );

Upvotes: 1

Related Questions