Compartilhar via


GetCompanyAddressByKey

Description

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

Parameters

Parameter

Type

Description

key

CompanyAddressKey

The company address key object that specifies the company address to retrieve.

context

Context

Specifies information about how the method will be called.

Return Value:

Value

Type

Description

GetCompanyAddressByKeyResult

CompanyAddress

A company address object.

Interfaces

  • Dynamics GP
  • Common
  • Field Service
  • Financials
  • Human Resources/Payroll
  • Inventory
  • Manufacturing
  • Project Accounting
  • Purchasing
  • Sales

Examples

The following C# example retrieves a the company address object with the key value "PRIMARY". The organization key property of the context object specifies the company key. The street address is displayed in a message box.

Cc508450.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;
            CompanyAddress companyAddress;
            CompanyAddressKey addressKey;

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

            // Be sure the default credentials are 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 object
            context.OrganizationKey = (OrganizationKey)companyKey;

            // Create a company address key object to retrieve the primary address
            addressKey = new CompanyAddressKey();
            addressKey.Id = "PRIMARY";

            // Retrieve the company address object
            companyAddress = wsDynamicsGP.GetCompanyAddressByKey(addressKey, context);

            // Display the primary street address
            MessageBox.Show("Primary street address: " + companyAddress.Line1);
        }
    }
}

Cc508450.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;
            CompanyAddress companyAddress;
            CompanyAddressKey addressKey;

            // 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 object
            context.OrganizationKey = (OrganizationKey)companyKey;

            // Create a company address key object to retrieve the primary address
            addressKey = new CompanyAddressKey();
            addressKey.Id = "PRIMARY";

            // Retrieve the company address object
            companyAddress = wsDynamicsGP.GetCompanyAddressByKey(addressKey, context);

            // Display the primary street address
            MessageBox.Show("Primary street address: " + companyAddress.Line1);

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