GetCompanyList


Description

Retrieves a list of company objects that match the specified criteria.

Parameters

Parameter

Type

Description

criteria

CompanyCriteria

The company criteria object that specifies which company objects are returned.

context

Context

Specifies information about how the method will be called.


Return Value:

Value

Type

Description

GetCompanyListResult

ArrayOfCompany

The list of company objects that match the specified criteria.


Interfaces

 

Examples

The following C# example retrieves the list of all company objects. The criteria object specifies a range that includes all possible company ID values. The total number of companies 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)
		{
			Context context;
			BetweenRestrictionOfNullableOfInt32 companyRestriction;
			CompanyCriteria companyCriteria;
			Company[] companyList;
		
			// Create an instance of the service
			DynamicsGP wsDynamicsGP = new DynamicsGP();

			// Be sure the default credentials are used
			wsDynamicsGP.UseDefaultCredentials = true;

			// Create a context object
			context = new Context();

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

			// Create a restriction object to query by company ID
			// Query for all possible company ID values
			companyRestriction = new BetweenRestrictionOfNullableOfInt32();
			companyRestriction.From = -32768;
			companyRestriction.To = 32767;

			// Create a company criteria object and add the restriction object 
			companyCriteria = new CompanyCriteria();
			companyCriteria.Id = companyRestriction;

			// Retrieve the list of companies
			companyList = wsDynamicsGP.GetCompanyList(companyCriteria, context);

			// Display the number of companies in a message box
			MessageBox.Show("Number of companies: " + companyList.Length.ToString());
	}
}
}

 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)
		{
			Context context;
			BetweenRestrictionOfNullableOfint companyRestriction;
			CompanyCriteria companyCriteria;
			Company[] companyList;
		
			// Create an instance of the service
			DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

			// Create a context object
			context = new Context();

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

			// Create a restriction object to query by company ID
			// Query for all possible company ID values
			companyRestriction = new BetweenRestrictionOfNullableOfint();
			companyRestriction.From = -32768;
			companyRestriction.To = 32767;

			// Create a company criteria object and add the restriction object 
			companyCriteria = new CompanyCriteria();
			companyCriteria.Id = companyRestriction;

			// Retrieve the list of companies
			companyList = wsDynamicsGP.GetCompanyList(companyCriteria, context);

			// Display the number of companies in a message box
			MessageBox.Show("Number of companies: " + companyList.Length.ToString());

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


Documentation Feedback