Compartilhar via


GetCurrencyAccessByKey

Description

Retrieves the currency access object based on the key values supplied. Information in this object indicates whether a company has access to a currency defined in Microsoft Dynamics GP.

Parameters

Parameter

Type

Description

key

CurrencyAccessKey

The currency access key object that specifies the company and currency.

context

Context

Specifies information about how the method will be called.

Return Value:

Value

Type

Description

GetCurrencyAccessByKeyResult

CurrencyAccess

The currency access object.

Interfaces

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

Examples

The following C# example retrieves the currency access object for the sample company and the New Zealand Dollar (NZD) currency. A message box is displayed, indicating whether the sample company has access to the currency.

Cc508460.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)
        {
            Context context;
            CurrencyKey currencyKey;
            CompanyKey companyKey;
            CurrencyAccessKey currencyAccessKey;
            CurrencyAccess currencyAccess;

            // 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
            context.OrganizationKey = null;

            // Create the currency access key object, specifying the
            // company and currency for which access will be examined
            companyKey = new CompanyKey();
            companyKey.Id = (-1);
            currencyKey = new CurrencyKey();
            currencyKey.ISOCode = "NZD";
            currencyAccessKey = new CurrencyAccessKey();
            currencyAccessKey.CompanyKey = companyKey;
            currencyAccessKey.CurrencyKey = currencyKey;

            // Retrieve the currency access object
            currencyAccess = wsDynamicsGP.GetCurrencyAccessByKey(currencyAccessKey, context);

            // Indicate whether the company has access to the currency
            if (currencyAccess.IsActive == true)
            {
                MessageBox.Show("Company has access");
            }
            else
            {
                MessageBox.Show("Company does not have access");
            }
        }
    }
}

Cc508460.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)
        {
            Context context;
            CurrencyKey currencyKey;
            CompanyKey companyKey;
            CurrencyAccessKey currencyAccessKey;
            CurrencyAccess currencyAccess;

            // 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
            context.OrganizationKey = null;

            // Create the currency access key object, specifying the
            // company and currency for which access will be examined
            companyKey = new CompanyKey();
            companyKey.Id = (-1);
            currencyKey = new CurrencyKey();
            currencyKey.ISOCode = "NZD";
            currencyAccessKey = new CurrencyAccessKey();
            currencyAccessKey.CompanyKey = companyKey;
            currencyAccessKey.CurrencyKey = currencyKey;

            // Retrieve the currency access object
            currencyAccess = wsDynamicsGP.GetCurrencyAccessByKey(currencyAccessKey, context);

            // Indicate whether the company has access to the currency
            if (currencyAccess.IsActive == true)
            {
                MessageBox.Show("Company has access");
            }
            else
            {
                MessageBox.Show("Company does not have access");
            }

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