Share via


GetCompletePolicyByKey

Description

Retrieves the policy instance based on the key value (GUID) for the policy and the role key supplied. The returned policy object will contain both the internal and the external behaviors.

Parameters

Parameter

Type

Description

key

PolicyKey

The policy key object ths specifies the policy to retrieve.

roleKey

RoleKey

The role key object that specifies the role for the policy instance.

context

Context

Specifies information about how the method will be called.

Return Value:

Value

Type

Description

GetCompletePolicyByKeyResult

Policy

The policy instance object.

Interfaces

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

Examples

The following C# example retrieves the default instance of the Update Sales Return policy. The GUID for the Update Sales Return policy was found in the Policy Reference for the Dynamics GP service. The role key object specifies the default policy instance. The total number of behaviors for the policy is displayed in a message box.

Cc508633.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;
            PolicyKey policyKey;
            Policy salesReturnPolicy;
            RoleKey roleKey;

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

            // Be sure that 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 the role key for the default role
            roleKey = new RoleKey();
            roleKey.Id = "00000000-0000-0000-0000-000000000000";

            // Get the complete update policy for sales returns
            policyKey = new PolicyKey();
            policyKey.Id = new Guid("a08b0c69-13bd-4a7b-bda9-d7902803364b");
            salesReturnPolicy = wsDynamicsGP.GetCompletePolicyByKey(policyKey, roleKey, context);

            MessageBox.Show(salesReturnPolicy.Behaviors.Length.ToString());
        }
    }
}

Cc508633.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;
            PolicyKey policyKey;
            Policy salesReturnPolicy;
            RoleKey roleKey;

            // 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 the role key for the default role
            roleKey = new RoleKey();
            roleKey.Id = "00000000-0000-0000-0000-000000000000";

            // Get the complete update policy for sales returns
            policyKey = new PolicyKey();
            policyKey.Id = new Guid("a08b0c69-13bd-4a7b-bda9-d7902803364b");
            salesReturnPolicy = wsDynamicsGP.GetCompletePolicyByKey(policyKey, roleKey, context);

            MessageBox.Show(salesReturnPolicy.Behaviors.Length.ToString());

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