This method creates a new corporate account.
Parameter |
Type |
Description |
---|---|---|
corporateAccount |
The corporate account object being created. |
|
context |
Specifies information about how the method will be called. |
|
policy |
Specifies the set of behaviors and behavior options to be applied during the operation. |
The following C# example creates a new corporate account. The customer object with the key value “COMMUNIC0001” becomes the parent corporate account. The customer object with the key value of “COMMUNIC0002“ is added as a member of the corporate account. All other properties of the corporate account are left as default values. A corporate account may also be created without specifying any members.
Legacy endpoint
using System; using System.Collections.Generic; using System.Text; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; CustomerKey parentCustomerKey; CustomerKey memberCustomerKey; CorporateAccount corporateAccount; CorporateAccountMemberKey memberKey; CorporateAccountMember member; Policy createCorpAccountPolicy; // Create an instance of the service DynamicsGP wsDynamicsGP = new DynamicsGP(); // Be sure the default credentials are used wsDynamicsGP.UseDefaultCredentials = true; // 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 parent corporate account parentCustomerKey = new CustomerKey(); parentCustomerKey.Id = "COMMUNIC0001"; // Create a customer key to specify the member memberCustomerKey = new CustomerKey(); memberCustomerKey.Id = "COMMUNIC0002"; // Create a corporate account member key // Use the customer keys to specify the parent and the member memberKey = new CorporateAccountMemberKey(); memberKey.CorporateAccountKey = parentCustomerKey; memberKey.CustomerKey = memberCustomerKey; // Create a corporate account member object // Populate the Key property with the member key object member = new CorporateAccountMember(); member.Key = memberKey; // Add the corporate account member to an array CorporateAccountMember[] corpAccountMembers = {member}; // Create a corporate account object corporateAccount = new CorporateAccount(); corporateAccount.Key = parentCustomerKey; corporateAccount.Members = corpAccountMembers; // Get the create policy for corporate accounts createCorpAccountPolicy = wsDynamicsGP.GetPolicyByOperation("CreateCorporateAccount", context); // Create the corporate account wsDynamicsGP.CreateCorporateAccount(corporateAccount, context, createCorpAccountPolicy); } } }
Native endpoint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; CustomerKey parentCustomerKey; CustomerKey memberCustomerKey; CorporateAccount corporateAccount; CorporateAccountMemberKey memberKey; CorporateAccountMember member; Policy createCorpAccountPolicy; // 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 parent corporate account parentCustomerKey = new CustomerKey(); parentCustomerKey.Id = "COMMUNIC0001"; // Create a customer key to specify the member memberCustomerKey = new CustomerKey(); memberCustomerKey.Id = "COMMUNIC0002"; // Create a corporate account member key // Use the customer keys to specify the parent and the member memberKey = new CorporateAccountMemberKey(); memberKey.CorporateAccountKey = parentCustomerKey; memberKey.CustomerKey = memberCustomerKey; // Create a corporate account member object // Populate the Key property with the member key object member = new CorporateAccountMember(); member.Key = memberKey; // Add the corporate account member to an array CorporateAccountMember[] corpAccountMembers = {member}; // Create a corporate account object corporateAccount = new CorporateAccount(); corporateAccount.Key = parentCustomerKey; corporateAccount.Members = corpAccountMembers; // Get the create policy for corporate accounts createCorpAccountPolicy = wsDynamicsGP.GetPolicyByOperation("CreateCorporateAccount", context); // Create the corporate account wsDynamicsGP.CreateCorporateAccount(corporateAccount, context, createCorpAccountPolicy); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }