【问题标题】:Acumatica change Shipping Terms on Sales Order creationAcumatica 在创建销售订单时更改运输条款
【发布时间】:2023-04-10 20:33:01
【问题描述】:

我正在使用 Acumatica 的基于合同的 API 从 ASP.net 应用程序创建销售订单。创建销售订单时,我需要更新销售订单上“运输设置”选项卡下的“运输条款”字段(见下文),但我找不到要在通过提供的 ASP.net 对象上使用的属性基于合约的 API。我将如何做到这一点?

这是我当前如何创建销售订单的代码:

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;
    }

}

更新: 根据 PatrickChen 的评论,我在 Acumatica“SalesOrderCustom”中创建了一个新的 Web 服务端点,其中我使用了所有默认字段,然后也将“ShippingTerms”添加到列表中。然后我将该 Web 服务导入到我的 .net 项目中(由于this 问题而有些头疼),并且能够使用该服务获取我想要添加运输条款的销售订单,并尝试更新它。代码执行正常,但是在 PUT 操作完成后,对象在 Acumatica 中没有更新,并且 ShippingTerms 属性返回为 NULL。我究竟做错了什么?代码如下:

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;
        }
    }
}

【问题讨论】:

  • 您使用的是默认端点吗?我必须创建一个新的来填充运输条款。
  • @PatrickChen 是的,我使用的是默认端点。您是如何创建新的?
  • @PatrickChen,我创建了一个新端点。这似乎是版本低于版本 6(我使用的是 5.30)的解决方案。我发现在版本 6 之后,您可以简单地扩展端点。如果你想发表你的答案,我会接受它
  • 很高兴它有帮助!

标签: acumatica


【解决方案1】:

从 Acumatica 6 开始,可以更新任何未包含在 Default 端点中的字段。此功能仅适用于实现第二版系统合约的端点:

以下示例展示了如何通过使用 @ 987654327@收藏:

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();
    }
}

在全新的 Acumatica 上使用扩展的默认基于合同的端点更新销售订单运输条款时,我也没有发现任何问题ERP 6.1 实例:

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();
    }
}

作为参考,添加我的扩展 Default 端点的屏幕截图,用于更新 SalesOrder 实体中的 Shipping Terms

【讨论】:

  • 这很完美!非常感谢你!我知道我使用的版本不是最新的,但我觉得第 26 页上关于自定义字段的文档here 应该提到这可以与“ShippingTerms”等非自定义字段一起使用。它仅用于“自定义”和自定义字段的上下文中,所以我认为这不是我的方案的一个选项。
  • 我尝试对“Salutation”字段(SalesOrder -> Shipping Settings -> Attention 字段)使用相同的自定义字段方法,因为它在标准 Contact 对象上也不存在,但是它不起作用。在这种情况下我需要做一些不同的事情吗?
  • 我在here上方的评论中添加了一个问题
【解决方案2】:

当我创建一个新的 6.0 端点时,我能够添加运输条款。 Acumatica 附带的默认端点不可扩展。

【讨论】:

  • 在 6.0 版之前你有没有让它工作?我创建了添加了运输条款的新端点,并且我通过首先获取销售订单对象,然后更新它,然后放置它来更新运输条款(如文档所述),但它不会更新 Acumatica 中的字段。也没有错误。
  • 我还没有构建一个 Web 服务来使用这个特定的端点。
  • 我更新了上面的答案以显示我的 Web 服务如何使用端点,这可能会有所帮助。但是,它仍然没有更新 ShippingTerms。有什么建议吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-06-15
  • 2017-08-03
  • 1970-01-01
  • 2015-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多