Update policy
An Update method requires an instance of the "update" policy for the object being updated. The update policy contains a set of behaviors that control various aspects of the update operation, such as how certain properties will be set, or whether additional actions 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 update method.
When you call an Update 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 update 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 Update method.
In the following C# example, a quantity for a line item in a sales order document is updated. The policy for the UpdateSalesOrder web method is retrieved. One behavior for this policy controls whether promotions are to be used. 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 that indicates that promotions should be used is located, based on the ID from the Dynamics GP Web Service Reference. The selected behavior option for the behavior is set to this specific behavior option.
** 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; SalesOrder salesOrder; Policy salesOrderUpdatePolicy; Behavior promotionBehavior; BehaviorOption includePromotionsBehaviorOption; 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 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 document key salesOrderKey = new SalesDocumentKey(); salesOrderKey.Id = "ORDST2227"; // Retrieve the sales order salesOrder = wsDynamicsGP.GetSalesOrderByKey(salesOrderKey, context); // Update the first line of the sales order salesOrder.Lines[0].Quantity.Value = 2; // Retrieve the update policy for sales orders salesOrderUpdatePolicy = wsDynamicsGP.GetPolicyByOperation ("UpdateSalesOrder", context); // Find the behavior in the list (from Web Service Reference) behaviorGUID = new Guid("2e58b57c-8fe1-4e98-bf04-371621f8e8b7"); promotionBehavior = new Behavior(); foreach (Behavior b in salesOrderUpdatePolicy.Behaviors) { if (b.Key.Id == behaviorGUID) { // Behavior was found promotionBehavior = b; break; } } // Find the behavior option (from Web Service Reference) behaviorOptionID = 1; includePromotionsBehaviorOption = new BehaviorOption(); foreach (BehaviorOption bo in promotionBehavior.Options) { if (bo.Key.Id == behaviorOptionID) { // Behavior option was found includePromotionsBehaviorOption = bo; break; } } // Set the selected behavior option promotionBehavior.SelectedOption = includePromotionsBehaviorOption; // Update the sales order object wsDynamicsGP.UpdateSalesOrder(salesOrder, context, salesOrderUpdatePolicy); } } }