CreateEmployeeAddress


Description

This method creates a new address and associates it with a specified employee.

Parameters

Parameter

Type

Description

employee

EmployeeAddress

The employee address object being created.

context

Context

Specifies information about how the method will be called.

policy

Policy

Specifies the set of behaviors and behavior options to be applied during the operation.


Interfaces

 

Examples

The following C# example creates a new address for an employee with the ID of “ACKE0001”. The example populates the State property. The remaining properties use default values. The CreateEmployeeAddress operation saves the address for the employee.

 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;
			EmployeeAddress employeeAddress;
			EmployeeKey employeeKey;
			EmployeeAddressKey employeeAddressKey;
			Policy employeeAddressCreatePolicy;

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

			// Be sure that default credentials are being 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
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create an employee key
			employeeKey = new EmployeeKey();
			employeeKey.Id = "ACKE0001";

			// Create an employee address key
			employeeAddressKey = new EmployeeAddressKey();
			employeeAddressKey.EmployeeKey = employeeKey;
			employeeAddressKey.Id = "Test address";

			// Create an employee address object
			employeeAddress = new EmployeeAddress();
			employeeAddress.Key = employeeAddressKey;
			employeeAddress.State = "CA";

			// Get the create policy for employee address objects
			employeeAddressCreatePolicy = wsDynamicsGP.GetPolicyByOperation(
				"CreateEmployeeAddress", context);

			// Create the employee address
			wsDynamicsGP.CreateEmployeeAddress(employeeAddress, context, employeeAddressCreatePolicy);
	}
}
}

 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;
			EmployeeAddress employeeAddress;
			EmployeeKey employeeKey;
			EmployeeAddressKey employeeAddressKey;
			Policy employeeAddressCreatePolicy;

			// 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
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create an employee key
			employeeKey = new EmployeeKey();
			employeeKey.Id = "ACKE0001";

			// Create an employee address key
			employeeAddressKey = new EmployeeAddressKey();
			employeeAddressKey.EmployeeKey = employeeKey;
			employeeAddressKey.Id = "Test address";

			// Create an employee address object
			employeeAddress = new EmployeeAddress();
			employeeAddress.Key = employeeAddressKey;
			employeeAddress.State = "CA";

			// Get the create policy for employee address objects
			employeeAddressCreatePolicy = wsDynamicsGP.GetPolicyByOperation(
				"CreateEmployeeAddress", context);

			// Create the employee address
			wsDynamicsGP.CreateEmployeeAddress(employeeAddress, context, employeeAddressCreatePolicy);

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


Documentation Feedback