Delete or void policy
A Delete or Void method requires an instance of the "delete" policy for the object being deleted or the "void" policy for the object being voided. The delete or void policy contains a set of behaviors that control various aspects of how the operation will be performed. The web service administrator controls all of the internal behavior options throught the Dynamics Security console. The external behaviors can be set by the application that is calling the delete or void method.
When you call a Delete or Void method for the Dynamics GP service, you must retrieve an instance of the policy used for that method. Do this using either the GetPolicyByOperation web method or the GetPolicyByKey web method. If the context object you pass to either method specifies a valid role for the user, the policy that is configured for that role will be returned. Otherwise, the default policy for the operation will be returned.
Once the policy for the delete or void operation has been retrieved, any external behaviors for the policy can be changed, if needed. The policy object will be passed to the web service Delete or Void method.
In the following C# example, a sales order is deleted. The policy for the DeleteSalesOrder web method is retrieved. One behavior for this policy controls whether posted deposits will be removed. The ID (GUID) for this behavior is looked up from the Dynamics GP Web Service Reference and used to locate the behavior. The behavior option specifying that posted deposits should not be removed is also looked up in the reference. Finally, the selected option for the behavior is set to the option to not remove posted deposits.
** Legacy endpoint**
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using DynamicsGPWebServiceSample.DynamicsGPService; using System.Xml; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; SalesDocumentKey salesOrderKey; Policy salesOrderDeletePolicy; Behavior removePostedDepositsBehavior; BehaviorOption doNotRemoveBehaviorOption; Guid behaviorGUID; int behaviorOptionID; // Create an instance of the web service DynamicsGP wsDynamicsGP = new DynamicsGP(); // Be sure the default credentials are used wsDynamicsGP.UseDefaultCredentials = true; // Create a context with which to call the web 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; context.CultureName = "en-US"; // Create a sales document key salesOrderKey = new SalesDocumentKey(); salesOrderKey.Id = "ORDST2226"; // Get the sales order delete policy salesOrderDeletePolicy = wsDynamicsGP.GetPolicyByOperation( "DeleteSalesOrder", context); // Find the behavior in the list (from Web Service Reference) behaviorGUID = new Guid("0f2c414b-fd12-4d83-940b-2bc0d65c3b77"); removePostedDepositsBehavior = new Behavior(); foreach (Behavior b in salesOrderDeletePolicy.Behaviors) { if (b.Key.Id == behaviorGUID) { // Behavior was found removePostedDepositsBehavior = b; break; } } // Find the behavior option (from Web Service Reference) behaviorOptionID = 0; doNotRemoveBehaviorOption = new BehaviorOption(); foreach (BehaviorOption bo in removePostedDepositsBehavior.Options) { if (bo.Key.Id == behaviorOptionID) { // Behavior option was found doNotRemoveBehaviorOption = bo; break; } } // Set selected behavior option to create a reversing transaction removePostedDepositsBehavior.SelectedOption = doNotRemoveBehaviorOption; // Delete the specified sales order wsDynamicsGP.DeleteSalesOrder(salesOrderKey, context, salesOrderDeletePolicy); } } }