Retrieves a single batch object based on the batch key value supplied.
Parameter |
Type |
Description |
---|---|---|
key |
The batch key object that specifies the batch to retrieve. |
|
context |
Specifies information about how the method will be called. |
Value |
Type |
Description |
---|---|---|
GetBatchByKeyResult |
A batch object. |
The following C# example retrieves a batch object with the batch key ID of “GL BATCH”, a batch key source of “GL_Normal” and a batch key created date of “5/9/2007”. A message box displays the batch name and it total.
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; DateTime createDate; BatchKey batchKey; Batch batch; // Create an instance of the 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 date time object to specify the batch create date createDate = new DateTime(2007,5, 9); // Create the batch key object batchKey = new BatchKey(); batchKey.Id = "GL BATCH"; batchKey.Source = "GL_Normal"; batchKey.CreatedDateTime = createDate; // Retrieve the specified batch batch = wsDynamicsGP.GetBatchByKey(batchKey, context); // Display the batch name and its total MessageBox.Show("Batch name: " + batch.Key.Id + " Total: " + batch.Total.Value.ToString("C")); } } }
Native endpoint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; DateTime createDate; BatchKey batchKey; Batch batch; // 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 date time object to specify the batch create date createDate = new DateTime(2007,5, 9); // Create the batch key object batchKey = new BatchKey(); batchKey.Id = "GL BATCH"; batchKey.Source = "GL_Normal"; batchKey.CreatedDateTime = createDate; // Retrieve the specified batch batch = wsDynamicsGP.GetBatchByKey(batchKey, context); // Display the batch name and its total MessageBox.Show("Batch name: " + batch.Key.Id + " Total: " + batch.Total.Value.ToString("C")); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }