首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建客户无地址- Dynamics GP

创建客户无地址- Dynamics GP
EN

Stack Overflow用户
提问于 2013-05-20 23:42:13
回答 2查看 735关注 0票数 0

我正在尝试在MS Dynamics GP中创建客户。下面是我的代码:

代码语言:javascript
复制
public void CreateGPCustomer(JMAOrder jd)
    {
        Customer cu = new Customer();
        cu.ModifiedDate = DateTime.Now;
        cu.IsActive = true;
        cu.Name = "Joseph Jones";
        cu.Shortname = "Joe";
        cu.StatementName = cu.Name;
        CustomerAddress cad = new CustomerAddress();
        cad.City = "Waltham";
        cad.ContactPerson = cu.Name;
        cad.CountryRegion = "US";
        cad.CreatedDate = DateTime.Now;
        cad.LastModifiedDate = DateTime.Now;
        cad.Line1 = "123 Main St";
        cad.Line2 = "12";
        PhoneNumber ph = new PhoneNumber();
        ph.CountryCode = "1";
        ph.Value = "7811234567";
        cad.Phone1 = ph;
        cad.PostalCode = "02452";
        cad.State = "MA";
        cu.Key = MakeCustomerKey("Joseph", "Jones");
        Policy p = wsDynamicsGP.GetPolicyByOperation("CreateCustomer", context);
        wsDynamicsGP.CreateCustomer(cu, context, p);
    }

我看到没有添加地址:

我遗漏了什么代码?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-21 21:30:28

创建客户地址与创建客户是两个独立的调用。请参阅Dynamics GP Web服务参考中的CreateCustomerAddress方法。

代码语言:javascript
复制
        CompanyKey companyKey;
        Context context;
        CustomerKey customerKey;
        CustomerAddressKey customerAddressKey;
        CustomerAddress customerAddress;
        Policy customerAddressCreatePolicy;

        // Create an instance of the service
        DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

        // Create a context with which to call the service
        context = new Context();

        // Specify which company to use (sample company)
        companyKey = new CompanyKey();
        companyKey.Id = (-1);

        // Set up the context object
        context.OrganizationKey = (OrganizationKey)companyKey;

        // Create a customer key to specify the customer
        customerKey = new CustomerKey();
        customerKey.Id = "AARONFIT0001";

        // Create a customer address key
        customerAddressKey = new CustomerAddressKey();
        customerAddressKey.CustomerKey = customerKey;
        customerAddressKey.Id = "BILLING";

        // Create a customer address object
        customerAddress = new CustomerAddress();
        customerAddress.Key = customerAddressKey;

        // Populate properties with address information
        customerAddress.Line1 = "11403 45 St. South";
        customerAddress.Line2 = "Billing Dept.";
        customerAddress.City = "Chicago";
        customerAddress.State = "IL";
        customerAddress.CountryRegion = "USA";

        // Get the create policy for the customer address
        customerAddressCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateCustomerAddress",
        context);

        // Create the customer address
        wsDynamicsGP.CreateCustomerAddress(customerAddress, context, customerAddressCreatePolicy);

        // Close the service
        if(wsDynamicsGP.State != CommunicationState.Faulted)
        {
            wsDynamicsGP.Close();
        }
票数 2
EN

Stack Overflow用户

发布于 2021-09-15 16:08:27

可以在同一调用中添加地址。您只需要包括地址:

代码语言:javascript
复制
  var customerKey = new CustomerKey() { Id = "Customer1" };

  var customer = new Customer()
  {
    Key = customerKey,
    ClassKey = new CustomerClassKey() { Id = "(DEFAULT)      " },
    Addresses = new CustomerAddress[] { 
      new CustomerAddress 
      {
        Key = new CustomerAddressKey { Id = "PRIMARY", CustomerKey = customerKey },  
        City = "MyCity",
        PostalCode = "61170",
        Line1 = "Line 1",
        Phone1 = new PhoneNumber{CountryCode = "US", Value = "111"},
        Phone2 = new PhoneNumber{CountryCode = "US", Value = "222"}
      },
      new CustomerAddress 
      {
        Key = new CustomerAddressKey { Id = "SHIPTO", CustomerKey = customerKey },  
        City = "MyCity",
        PostalCode = "2222",
        Line1 = "Line 1",
        Phone1 = new PhoneNumber{CountryCode = "US", Value = "333"},
        Phone2 = new PhoneNumber{CountryCode = "US", Value = "444"}
      }
    },
  };
  var createCustomerPolicy = client.GetPolicyByOperation("CreateCustomer", context);
  client.CreateCustomer(customer, context, createCustomerPolicy);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16653156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档