Retrieves the policy instance based on the key value (GUID) for the policy. The appropriate policy instance will be retrieved for the user, company, and role specified by the context object. The returned policy object will contain only the external behaviors.
Parameter |
Type |
Description |
---|---|---|
key |
The policy key object ths specifies the policy to retrieve. |
|
context |
Specifies information about how the method will be called. |
Value |
Type |
Description |
---|---|---|
GetPolicyByKeyResult |
The policy instance object. |
The following C# example updates a sales return document. The GetPolicyByKey method is used to retrieve the policy instance to use for the method call. The GUID for the Update Sales Return policy was found in the Policy Reference for the Dynamics GP service.
Legacy endpoint
using System; using System.Collections.Generic; using System.Text; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; SalesDocumentKey salesReturnKey; SalesReturn salesReturn; PolicyKey policyKey; Policy salesReturnPolicy; // 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 a Sales Return key and specify the sales return salesReturnKey = new SalesDocumentKey(); salesReturnKey.Id = "STDINV2257"; // Retrieve the sales return object salesReturn = wsDynamicsGP.GetSalesReturnByKey(salesReturnKey, context); // Set the comment property salesReturn.Comment = "Return was approved"; // Get the update policy for sales returns policyKey = new PolicyKey(); policyKey.Id = new Guid("a08b0c69-13bd-4a7b-bda9-d7902803364b"); salesReturnPolicy = wsDynamicsGP.GetPolicyByKey(policyKey, context); // Update the sales return object wsDynamicsGP.UpdateSalesReturn(salesReturn, context, salesReturnPolicy); } } }
Native endpoint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; SalesDocumentKey salesReturnKey; SalesReturn salesReturn; PolicyKey policyKey; Policy salesReturnPolicy; // 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 Sales Return key and specify the sales return salesReturnKey = new SalesDocumentKey(); salesReturnKey.Id = "STDINV2257"; // Retrieve the sales return object salesReturn = wsDynamicsGP.GetSalesReturnByKey(salesReturnKey, context); // Set the comment property salesReturn.Comment = "Return was approved"; // Get the update policy for sales returns policyKey = new PolicyKey(); policyKey.Id = new Guid("a08b0c69-13bd-4a7b-bda9-d7902803364b"); salesReturnPolicy = wsDynamicsGP.GetPolicyByKey(policyKey, context); // Update the sales return object wsDynamicsGP.UpdateSalesReturn(salesReturn, context, salesReturnPolicy); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }