Select Page
November 11, 2011

C Sharp Program to get 1000 records
in Microsoft Dynamics GP 2010 using Web Services

Author ALLAN JONES
Category Blog | Integration |
Share

Handling 1000+ records in MS Dynamics Great Plains
When a call is made to GetCustomerList method, only the first 1000 records are received. . This is not possible in the GP 10 because the number of records for the GetCustomerList is fixed to 1000 in the Dynamics GP Web Service. To receive the complete list of the customers from the RM00101 table, use the following code.
To call more than 1000 records call the GetCustomerList in a loop. Use the last customer number from the first 1000 records and get the next 1000 records from that customer number.
C# Program Code
CompanyKey companyKey;
Context context;
// Create an instance of the web service
GPWebReference.DynamicsGP wsDynamicsGP = new DynamicsGP();
//Web Service credentials
wsDynamicsGP.Credentials = new System.Net.NetworkCredential(“DomainUserName”, “DomainPassword”,”DomainName”);
// 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
context.OrganizationKey = (OrganizationKey)companyKey;
context.CultureName = “en-US”;
// Create variables to store the last customer ID and Name returned by the GetCustomerList method.
string strLastCustomerNumber = “”;
string strLastCustomerName = “”;
// When results are returned by method call, this variable will be set to 1
int intResultsExist = 0;
// Create a CustomerCriteria object
CustomerCriteria customerCriteria = new CustomerCriteria();
// Create a LikeRestrictionOfstring for Customer Name that starts with a C
LikeRestrictionOfString customerNameCriteria = new LikeRestrictionOfString();
customerNameCriteria.Like = “%”;
// Create a LikeRestriction for Customer ID used later
LikeRestrictionOfString customerIDCriteria = new LikeRestrictionOfString();
// Create CustomerSummary object
CustomerSummary[] customerSummaryList;
try
{
// Set Customer Name Criteria for first GetCustomerList call
customerCriteria.Name = customerNameCriteria;
// Retrieve the list of customer summaries
customerSummaryList = wsDynamicsGP.GetCustomerList(customerCriteria, context);
// Create a for loop.
int intCustomerCount = 0;
// Create a counter to track number of customers
int totalCustomerCount = 0;
/***********Do some operation to save the customers into a temporary object ***********/
// Obtain the customer Id and name of last customer returned.
strLastCustomerNumber = customerSummaryList[customerSummaryList.Length – 1].Key.Id;
strLastCustomerName = customerSummaryList[customerSummaryList.Length – 1].Name;
// Set the total counter
totalCustomerCount = intCustomerCount;
// Check the iCustomerCount to see we need to call the GetCustomerList method again.
if (intCustomerCount >= 1000)
{
// Set iResultsExist = 1 which indicates results are still being returned from the Web service method call
intResultsExist = 1;
// While iResultsExist = 1, call the GetCustomerList
while (intResultsExist == 1)
{
/* Add Criteria restriction to return customers where the Customer ID is larger than the last Customer ID returned.*/
customerIDCriteria.GreaterThan = strLastCustomerNumber;
customerCriteria.Id = customerIDCriteria;
//Call GetCustomerList to obtain the next 1000 customers
customerSummaryList = wsDynamicsGP.GetCustomerList(customerCriteria, context);
/***********Do some operation to add these customers to the temporary object***********/
//Obtain the Id of the last customer returned.
strLastCustomerNumber = customerSummaryList[intCustomerCount].Key.Id;
strLastCustomerName = customerSummaryList[intCustomerCount].Name;
// Add to the Total Customer Counter
totalCustomerCount = totalCustomerCount + intCustomerCount;
// Evaluate whether iCustomerCount is larger than or equal to 1000. If it is, set the iResultsExist and call the GetCustomerList method again.
if (intCustomerCount >= 1000)
{
//Set iResultsExist = 1 and call GetCustomerList again.
intResultsExist = 1;
}
else
{
//Set iResultsExist = 0 and exit the while statement
intResultsExist = 0;
}
}
}
}
catch (Exception ex)
{
throw ex;
}

Recent Blogs