簡體   English   中英

如何使用DotNetSDataClient在Saleslogix Infor CRM中創建新聯系人

[英]How to create a new contact in Saleslogix Infor CRM using DotNetSDataClient

我正在嘗試使用DotNetSDataClient庫在Infor CRM中添加新聯系人。 我試圖按照“ 創建”部分下的說明文檔進行操作。 當我運行示例代碼時,收到錯誤消息“需要聯系人的帳戶”。 這是有道理的,因為我認為數據庫中的每個聯系人都必須與一個帳戶關聯。 我修改了代碼以指定現有帳戶,但現在收到錯誤消息“很抱歉,您遇到了錯誤。如果適用,請重試。” 帶有內部異常,“刪除服務器返回錯誤:(500)內部服務器錯誤。”

這是我的代碼。

public void someFunction(){
    var client = new SDataClient("https://domain/sdata/slx/dynamic/-/")
    {
        UserName = "username",
        Password = "password"
    };

    var contact = new Contact
    {
        Account = new Account
        {
            AccountName = "accountName",
            Id = "accountId"
        },
        Address = new Address
        {
            Address1 = "1234 Address",
            City = "someCity",
            PostalCode = "12345",
            State = "ST"
        },
        FirstName = "John",
        LastName = "Doe"
    };

    var contactOptions = new SDataPayloadOptions { Include = "Address" };

    try
    {
        contact = client.Post(contact, null, contactOptions);
    }
    catch (Exception ex)
    {
        var error = ex.Message;
    }
}

[SDataPath("accounts")]
public class Account
{
    [SDataProtocolProperty(SDataProtocolProperty.Key)]
    public string Id { get; set; }

    public string AccountName { get; set; }
    public List<Contact> Contacts { get; set; }
    public string Status { get; set; }
    public string Type { get; set; }
}

[SDataPath("contacts")]
public class Contact
{
    [SDataProtocolProperty(SDataProtocolProperty.Key)]
    public string Id { get; set; }

    public Account Account { get; set; }
    public Address Address { get; set; }
    public string Email { get; set; }
    public string FirstName { get; set; }
    public string FullName { get; set; }
    public string LastName { get; set; }
    public DateTime? ModifyDate { get; set; }
    public string Status { get; set; }
}

[SDataPath("addresses")]
public class Address
{
    [SDataProtocolProperty]
    public string Key { get; set; }
    public string Address1 { get; set; }
    public string Address3 { get; set; }
    public string Address2 { get; set; }
    public string City { get; set; }
    public string CountryCode { get; set; }
    public string Description { get; set; }
    public string PostalCode { get; set; }
    public string State { get; set; }
    public string Street { get; set; }
}

有人對我在做什么錯有任何想法嗎?

我還將這個問題發布在GitHub上,Ryan Farley提供了答案。 我想在這里包括它,以防其他人需要此解決方案。

問題在於庫如何序列化數據。 這是Ryan的回應:

“這里真正的問題是Account的POCO具有聯系人集合。DotNetSDataClient正在將其序列化為null,而SData服務器則不喜歡這樣。即使將該集合設置為new List()也會失敗,因為它將被序列化as []。應該看起來像什么

"Contacts": { "$resources": [] }

與現有的父級或相關實體進行POST時,SData期望僅接收$ key,而不會收到其他任何消息。 因此,當Contact類被序列化時,應該與聯系數據一起發送的是

"Account": { "$key":"AXXX00000001" }

僅此而已,但事實並非如此,該庫正在序列化並發送所有內容。”

此時,解決方案是創建一個僅具有id(鍵)屬性的帳戶類。

[SDataPath("accounts")]
public class Account
{
    [SDataProtocolProperty(SDataProtocolProperty.Key)]
    public string Id { get; set; }
}

在某些時候,可能會更新DotNetSDataClient庫以處理這種情況,但是現在這是解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM