GetCompanyByKey


Description

Retrieves a single company object based on the key value supplied.

Parameters

Parameter

Type

Description

key

CompanyKey

The company key object that specifies the company to retrieve.

context

Context

Specifies information about how the method will be called.


Return Value:

Value

Type

Description

GetCompanyByKeyResult

Company

A company object.


Interfaces

 

Examples

The following C# example retrieves the company with the key value “-1”. The name of the company 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;
			Company company;

			// 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();

			// Set up the context object
			// To retrieve from the system database, set the organization key to null
			context.OrganizationKey = null;

			// Specify a company to retrieve (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Retrieve the company object for the sample company
			company = wsDynamicsGP.GetCompanyByKey(companyKey, context);

			// Display the company name 
			MessageBox.Show("Company name: " + company.Name);
	}
}
}

 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;
			Company company;

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

			// Create a context with which to call the service
			context = new Context();

			// Set up the context object
			// To retrieve from the system database, set the organization key to null
			context.OrganizationKey = null;

			// Specify a company to retrieve (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Retrieve the company object for the sample company
			company = wsDynamicsGP.GetCompanyByKey(companyKey, context);

			// Display the company name 
			MessageBox.Show("Company name: " + company.Name);

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


Documentation Feedback