Retrieves a single validation result object from the log based on the logId value supplied.
Parameter |
Type |
Description |
---|---|---|
logId |
A key that uniquely identifies the logged validation result. |
|
context |
Specifies information about how the method will be called. |
Value |
Type |
Description |
---|---|---|
GetLoggedValidationResultByKeyResult |
A logged validation result object. |
The following C# example creates two validation errors. The validation errors cause a soap exception that contains the logid of the logged validation exception. The logid is used to to retrieve the validation result object. The number of validation errors in the validation result object is displayed in a message box.
Legacy endpoint
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Web.Services.Protocols; using System.Xml; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; VendorKey vendorKey; Vendor vendor; Policy policy; ValidationResult validationResult; // 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(); // Specify which company to use (sample company) companyKey = new CompanyKey(); companyKey.Id = (-1); // Set up the context context.OrganizationKey = (OrganizationKey)companyKey; // Create a vendor key of the vendor to be udpated vendorKey = new VendorKey(); vendorKey.Id = "ACETRAVE0001"; // Create a vendor object vendor = new Vendor(); vendor.Key = vendorKey; // Set a pair of properties to create two validation errors vendor.DiscountGracePeriod = 100; vendor.DueDateGracePeriod = 100; try { // Create a policy object policy = wsDynamicsGP.GetPolicyByOperation("UpdateVendor", context); // Attempt to update the vendor wsDynamicsGP.UpdateVendor(vendor, context, policy); } catch(SoapException soapErr) { // Try retrieving the Message node XmlDocument doc = new XmlDocument(); XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable); nsManager.AddNamespace("sm", "http://schemas.datacontract.org/2004/07/System.ServiceModel"); doc.LoadXml(soapErr.Detail.InnerXml); XmlNode node = doc.SelectSingleNode( "//sm:InnerException//sm:Message", nsManager); if (node != null) { // Use the GUID retrieved to load the validation details Guid LogId = new Guid(node.InnerText.Trim()); // Get the validation result object validationResult = wsDynamicsGP.GetLoggedValidationResultByKey(guid, context); // Display the number of validation exceptions MessageBox.Show("Number of validation exceptions: " + validationResult.Errors.Length.ToString()); } } } } }
Native endpoint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Web.Services.Protocols; using DynamicsGPWebServiceSample.DynamicsGPService; using System.ServiceModel; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; VendorKey vendorKey; Vendor vendor; Policy policy; ValidationResult validationResult; // 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 context.OrganizationKey = (OrganizationKey)companyKey; // Create a vendor key of the vendor to be udpated vendorKey = new VendorKey(); vendorKey.Id = "ACETRAVE0001"; // Create a vendor object vendor = new Vendor(); vendor.Key = vendorKey; // Set a pair of properties to create two validation errors vendor.DiscountGracePeriod = 100; vendor.DueDateGracePeriod = 100; try { // Create a policy object policy = wsDynamicsGP.GetPolicyByOperation("UpdateVendor", context); // Attempt to update the vendor wsDynamicsGP.UpdateVendor(vendor, context, policy); } catch (FaultException<System.ServiceModel.ExceptionDetail> ex) { // If this is a validation exception, retrieve the details if (ex.Detail.InnerException != null) { // Create a guid for the logid value in the exception Guid guid = new Guid(ex.Detail.InnerException.Message.Trim()); // Get the validation result object validationResult = wsDynamicsGP.GetLoggedValidationResultByKey(guid, context); // Display the number of validation exceptions MessageBox.Show("Number of validation exceptions: " + validationResult.Errors.Length.ToString()); } } // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }