UpdateEmployee


Description

Updates the specified employee object, storing the current values in the database.

Parameters

Parameter

Type

Description

employee

Employee

The employee object that is being updated.

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 retrieves and updates the status property of the employee with an Id of “ACKE0001”. The update sets the Status property to “Other. The UpdateEmployee operation saves the changes to the employee object to the database.

 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;
			Employee employee;
			EmployeeKey employeeKey;
			Policy employeeUpdatePolicy;

			// 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";

			// Retrieve the employee object
			employee = wsDynamicsGP.GetEmployeeByKey(employeeKey, context);

			// Change the status property of the employee object
			employee.HRStatus = HRStatus.Other;

			// Get the update policy for employee objects
			employeeUpdatePolicy = wsDynamicsGP.GetPolicyByOperation("UpdateEmployee", context);

			// Update the employee
			wsDynamicsGP.UpdateEmployee(employee, context, employeeUpdatePolicy);
	}
}
}

 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;
			Employee employee;
			EmployeeKey employeeKey;
			Policy employeeUpdatePolicy;

			// 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";

			// Retrieve the employee object
			employee = wsDynamicsGP.GetEmployeeByKey(employeeKey, context);

			// Change the status property of the employee object
			employee.HRStatus = HRStatus.Other;

			// Get the update policy for employee objects
			employeeUpdatePolicy = wsDynamicsGP.GetPolicyByOperation("UpdateEmployee", context);

			// Update the employee
			wsDynamicsGP.UpdateEmployee(employee, context, employeeUpdatePolicy);

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


Documentation Feedback