2017-02-04 48 views
0

我正在使用基於屏幕的API導入客戶。我想通過API提交時使用電子郵件地址作爲識別碼。換句話說,在提交客戶時,它將使用電子郵件地址來確定該客戶是否已經存在。Acumatica:如何使用EMAIL作爲關鍵VIA Web API插入/更新客戶?

基本上我想要完成的任務是在下面的網站,但使用基於屏幕的API,而不是: http://www.timrodman.com/importing-new-customers-email-address-acumatica/

我的代碼如下:

 using (Screen context = WebServiceConnector.InitializeWebService()) 
     { 
      try 
      { 
       AR303000Content customerSchema = context.AR303000GetSchema(); 

       // ATTEMPT #1: Tried setting the CustomerID field name to "AcctCD!EMail" 
       customerSchema.CustomerSummary.CustomerID.FieldName += "!" + customerSchema.GeneralInfoMainContact.Email.FieldName; 

       // ATTEMPT #2: Tried setting the CustomerID field name to "AcctCD!Contact__eMail" 
       //customerSchema.CustomerSummary.CustomerID.FieldName = "AcctCD!Contact__eMail"; 

       // Tried COMMIT = true and false 
       customerSchema.CustomerSummary.CustomerID.Commit = false; 

       // Left as default and tried "ID" 
       customerSchema.CustomerSummary.CustomerID.Value = "ID"; 

       var commands = new List<Command>() 
       { 
        new Value 
        { 
        Value = customer.Email, 
        LinkedCommand = customerSchema.CustomerSummary.CustomerID 
        }, 
        new Value 
        { 
        Value = customer.Name, 
        LinkedCommand = customerSchema.CustomerSummary.CustomerName 
        }, 
        new Value 
        { 
        Value = customer.Class, 
        LinkedCommand = customerSchema.GeneralInfoFinancialSettings.CustomerClass 
        }, 
        new Value 
        { 
        Value = customer.Email, 
        LinkedCommand = customerSchema.GeneralInfoMainContact.Email 
        }, 
        new Value 
        { 
        Value = customer.CountryCode, 
        LinkedCommand = customerSchema.GeneralInfoMainAddress.Country 
        }, 
        customerSchema.Actions.Save, 
        customerSchema.CustomerSummary.CustomerID 
       }; 

       c = context.AR303000Submit(commands.ToArray())[0]; 

      } 
      catch (Exception e) 
      { 
      } 
      finally 
      { 
       context.Logout(); 
      } 
     } 

回答

2

您應該配置搜索的客戶通過電子郵件記錄 地址: a。在創建命令數組的代碼之前,在字符串變量initialCustomerIDFieldName中保存CustomerID字段的初始字段名稱。

b。在initialCustomerIDFieldName變量的定義之後,使用CustomerID關鍵字字段的屬性值初始化Field對象的屬性。

c。將Field對象的FieldName屬性(現在等於CustomerID關鍵字段的FieldName屬性的值)與!和FilterEmail服務命令的FieldName屬性。 d)。在Command對象數組中的Value命令中,將Value屬性設置爲customerMainContactEmail變量(設置爲[email protected]),將LinkedCommand屬性設置爲創建的Field對象。

以下代碼說明了此過程。

AR303000Content custSchema = PX.Soap.Helper.GetSchema<AR303000Content>(context); 
//Save the initial field name of the CustomerID field string 
initialCustomerIDFieldName = custSchema.CustomerSummary.CustomerID.FieldName; 
//Configure the command that searches for a customer record 
//by using the FilterEmail service command 
Field customerIDSelector = custSchema.CustomerSummary.CustomerID; 
customerIDSelector.FieldName += "!" + 
custSchema.CustomerSummary.ServiceCommands.FilterEmail.FieldName; 
var commands = new Command[] 
{ 
    new Value 
    { 
     Value = customerMainContactEmail, 
     LinkedCommand = customerIDSelector 
    }, 
}; 

有一個在Acumatica online course for Screen-Based API

更多信息和示例