CreateEmployee

Description

This method creates a new employee.

Parameters

Parameter

Type

Description

employee

Employee

The employee 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

  • Dynamics GP
  • Human Resources/Payroll

Examples

The following C# example creates a new employee with the key value "ABARR". The example populates the required Name, TaxIdentifier, DepartmentKey, and PositionKey properties. The remaining properties use default values. The CreateEmployee operation saves the new employee.

Cc713398.LegacyEndpoint(en-us,MSDN.10).gif** 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 employeeName;
            DepartmentKey departmentKey;
            PositionKey positionKey;
            Policy employeePolicy;

            // 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 a new employee object
            employee = new Employee();

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

            // Set properties for the new employee

            // Specify the employee name
            employeeName = new Name();
            employeeName.Given = "Adam";
            employeeName.Family = "Barr";
            employee.Name = employeeName;

            // Specify the tax identifier
            employee.TaxIdentifier = "917238675";

            // Specify the department -- Sales
            departmentKey = new DepartmentKey();
            departmentKey.Id = "SALE";
            employee.DepartmentKey = departmentKey;

            // Specify the employee position -- Field Sales Representitive
            positionKey = new PositionKey();
            positionKey.Id = "FSR";
            employee.PositionKey = positionKey;

            // Get the create policy for the employee
            employeePolicy = wsDynamicsGP.GetPolicyByOperation("CreateEmployee", context);

            // Create the employee
            wsDynamicsGP.CreateEmployee(employee, context, employeePolicy);
        }
    }
}

Cc713398.NativeEndpoint(en-us,MSDN.10).gif** Native endpoint **

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
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 employeeName;
            DepartmentKey departmentKey;
            PositionKey positionKey;
            Policy employeePolicy;

            // 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 a new employee object
            employee = new Employee();

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

            // Set properties for the new employee

            // Specify the employee name
            employeeName = new Name();
            employeeName.Given = "Adam";
            employeeName.Family = "Barr";
            employee.Name = employeeName;

            // Specify the tax identifier
            employee.TaxIdentifier = "917238675";

            // Specify the department -- Sales
            departmentKey = new DepartmentKey();
            departmentKey.Id = "SALE";
            employee.DepartmentKey = departmentKey;

            // Specify the employee position -- Field Sales Representitive
            positionKey = new PositionKey();
            positionKey.Id = "FSR";
            employee.PositionKey = positionKey;

            // Get the create policy for the employee
            employeePolicy = wsDynamicsGP.GetPolicyByOperation("CreateEmployee", context);

            // Create the employee
            wsDynamicsGP.CreateEmployee(employee, context, employeePolicy);

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