Acumatica change Shipping Terms on Sales Order creation

∥☆過路亽.° 提交于 2019-12-10 11:48:29

问题


I'm using Acumatica's contract based API to create sales order from an ASP.net application. I need to update the "Shipping Terms" field under the "Shipping Settings" tab on a Sales Order when I create it (see below), but I can not find the property to use on the ASP.net objects that are provided through the contract based API. How would I accomplish this?

Here is my current code for how I create the sales order:

using (DefaultSoapClient client = new DefaultSoapClient(binding, address))
{
    //Sales order data
    string customerID = "CUST1234;
    string orderDescription = "Automated Order";
    string customerOrder = "TEST";

    var orderDetails = new List<SalesOrderDetail>();

    foreach(var lineItem in order.line_items)
    {
        orderDetails.Add(new SalesOrderDetail {
            InventoryID = new StringValue { Value = lineItem.sku },
            Quantity = new DecimalValue { Value = lineItem.quantity },
            UnitPrice = new DecimalValue { Value = Decimal.Parse(lineItem.price) }, //TODO this should only be done for MHR owned sites
            UOM = new StringValue { Value = "EACH" },

        });
    }


    //Specify the values of a new sales order
    SalesOrder orderToBeCreated = new SalesOrder
    {
        OrderType = new StringValue { Value = "SO" },
        CustomerID = new StringValue { Value = customerID },
        Description = new StringValue { Value = orderDescription },
        CustomerOrder = new StringValue { Value = customerOrder },
        ExternalReference = new StringValue { Value = order.order_number.ToString() },
        Details = orderDetails.ToArray<SalesOrderDetail>(),
        ShippingAddressOverride = new BooleanValue { Value = true },
        ShippingContactOverride = new BooleanValue { Value = true },
        ShippingContact = new Contact()
        {
            DisplayName = new StringValue { Value = order.shipping_address.first_name + " " + order.shipping_address.last_name },
            FirstName = new StringValue { Value = order.shipping_address.first_name },
            LastName = new StringValue { Value = order.shipping_address.last_name },
            Address = new Address()
            {
                AddressLine1 = new StringValue { Value = order.shipping_address.address_1 },
                AddressLine2 = new StringValue { Value = order.shipping_address.address_2 },
                City = new StringValue { Value = order.shipping_address.city },
                State = new StringValue { Value = order.shipping_address.state },
                Country = new StringValue { Value = order.shipping_address.country },
                PostalCode = new StringValue { Value = order.shipping_address.postcode }
            }
        },

    };

    client.Login(_acumaticaUid, _acumaticaPwd, _acumaticaCompany, null, null);

    //Create a sales order with the specified values
    try
    {
        SalesOrder newOrder = (SalesOrder)await client.PutAsync(orderToBeCreated);

        client.Logout();

        return newOrder;
    }
    catch (Exception e)
    {
        //order addition to Acumatica failed, update the order status in Woo Commerce
        client.Logout();
        Console.WriteLine("Acumatica could not add specified entity: " + e);
        return null;
    }

}

UPDATE: Based on PatrickChen's comment, I created a new web service endpoint in Acumatica "SalesOrderCustom", where I used all of the default fields and then added "ShippingTerms" to the list as well. I then imported that web service into my .net project (with some headache due to this issue) and was able to use the service to GET the sales order I wanted to add shipping terms to, and try to update it. The code executes ok, but after the PUT operation is done, the object is NOT updated in Acumatica and the ShippingTerms property is returned as NULL. What am I doing wrong? Code below:

public async Task<SalesOrderCustom> UpdateShippingTerms(string customerOrder, string originStore, string shippingSpeed)
{
    var binding = CreateNewBinding(true, 655360000, 655360000);

    var address = new EndpointAddress(ConfigurationManager.AppSettings["AcumaticaCustomUrl"]);

    var soToBeFound = new SalesOrderCustom()
    {
        OrderType = new StringSearch { Value = "SO" },
        CustomerOrder = new StringSearch { Value = customerOrder }
    };

    using (DefaultSoapClient client = new DefaultSoapClient(binding, address))
    {
        client.Login(_acumaticaUid, _acumaticaPwd, _acumaticaCompany, null, null);

        try
        {
            var soToBeUpdated = (SalesOrderCustom) await client.GetAsync(soToBeFound);

            soToBeUpdated.ShippingTerms = new StringValue { Value = "USPS 1 CLS" };

            var updatedOrder = (SalesOrderCustom)await client.PutAsync(soToBeUpdated);
            //ShippingTerms is still NULL on returned object even after updating the object!!! WHY???

            client.Logout();
            return updatedOrder;
        }
        catch (Exception e)
        {
            client.Logout();
            Console.WriteLine("Acumatica could not find specified entity: " + e);
            return null;
        }
    }
}

回答1:


Starting Acumatica 6, it's possible to update any field, not included into the Default endpoint. This feature is only available for endpoints implementing system contract of the 2nd version:

Below is the sample showing how to change Shipping Terms for a Sales Order with the Default Contract-Based endpoint by working with the CustomFields collection:

using (var client = new DefaultSoapClient())
{
    client.Login("admin", "123", null, null, null);
    try
    {
        var order = new SalesOrder()
        {
            OrderType = new StringSearch { Value = "SO" },
            OrderNbr = new StringSearch { Value = "SO003729" }
        };
        order = client.Get(order) as SalesOrder;
        order.CustomFields = new CustomField[]
        {
            new CustomStringField
            {
                fieldName = "ShipTermsID",
                viewName = "CurrentDocument",
                Value = new StringValue { Value = "FLATRATE2" }
            }
        };
        client.Put(order);
    }
    finally
    {
        client.Logout();
    }
}

No issues also noticed on my end when updating Sales Order Shipping Terms with the extended Default Contract-Based endpoint on a brand new Acumatica ERP 6.1 instance:

using (var client = new DefaultSoapClient())
{
    client.Login("admin", "123", null, null, null);
    try
    {
        var order = new SalesOrder()
        {
            OrderType = new StringSearch { Value = "SO" },
            OrderNbr = new StringSearch { Value = "SO003729" }
        };
        order = client.Get(order) as SalesOrder;
        order.ShippingTerms = new StringValue { Value = "FLATRATE1" };
        client.Put(order);
    }
    finally
    {
        client.Logout();
    }
}

For reference, adding screenshot of my extended Default endpoint used to update Shipping Terms in the SalesOrder entity:




回答2:


I was able to add Shipping Terms when I created a new 6.0 endpoint. The default endpoint that ships with Acumatica is not extendable.



来源:https://stackoverflow.com/questions/42676451/acumatica-change-shipping-terms-on-sales-order-creation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!