Retrieves a single employee object based on the key value supplied. The value returned by this method can be affected by entity ID filtering.
Parameter |
Type |
Description |
---|---|---|
key |
The employee key object that specifies the employee to retrieve. |
|
context |
Specifies information about how the method will be called. |
Value |
Type |
Description |
---|---|---|
GetEmployeeByKeyResult |
An employee object. |
The following C# example retrieves the employee with the key value “ACKE0001”. The name information for the employee is displayed in a message box.
Legacy endpoint
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; Employee employee; EmployeeKey employeeKey; Name name; // 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); // Retrieve the employee name information name = new Name(); name = employee.Name; // Display the name information MessageBox.Show(name.Given + " " + name.Middle + " " + name.Family); } } }
Native endpoint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; Employee employee; EmployeeKey employeeKey; Name name; // 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); // Retrieve the employee name information name = new Name(); name = employee.Name; // Display the name information MessageBox.Show(name.Given + " " + name.Middle + " " + name.Family); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }