Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following C# code example shows how the Scope property of the criteria object is used. This example retrieves the historical sales orders for the current user. The Scope property of the Sales Order Criteria object is set to ReturnBasedOnSalespersonID, so that only documents associated with the current user will be returned. To work, this example requires that the user has access to the "Query Sales Orders Based On User" operation for the Dynamics GP service. There must also be an entity ID assignment that maps the user to a Salesperson ID in Microsoft Dynamics GP.
** Legacy endpoint**
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Web.Services.Protocols;
using DynamicsGPWebServiceSample.DynamicsGPService;
namespace DynamicsGPWebServiceSample
{
class Program
{
static void Main(string[] args)
{
CompanyKey companyKey;
Context context;
ListRestrictionOfNullableOfSalesTransactionState
transactionStateRestriction;
SalesOrderCriteria salesOrderCriteria;
SalesOrderSummary[] salesOrderSummary;
// 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 transaction state restriction object
transactionStateRestriction = new
ListRestrictionOfNullableOfSalesTransactionState();
transactionStateRestriction.EqualValue =
SalesTransactionState.History;
// Create a sales order criteria object
// Retrieve summary objects for historical sales orders
salesOrderCriteria = new SalesOrderCriteria();
salesOrderCriteria.TransactionState =
transactionStateRestriction;
// Specify the scope so that transactions for only the current
// user are retrieved
salesOrderCriteria.Scope =
SalesDocumentScope.ReturnBasedonSalespersonId;
try
{
// Retrieve the sales order summaries specified
salesOrderSummary =
wsDynamicsGP.GetSalesOrderList(salesOrderCriteria, context);
// Display the ID and amount of each summary object
StringBuilder summaryList = new StringBuilder();
foreach (SalesOrderSummary a in salesOrderSummary)
{
summaryList.AppendLine("Order number: " + a.Key.Id +
" Order amount: " + a.TotalAmount.Value.ToString("C"));
}
MessageBox.Show(summaryList.ToString());
}
catch (SoapException soapErr)
{
MessageBox.Show(soapErr.Message);
}
}
}
}
** Native endpoint **
using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WebServiceSample.DynamicsGPService;
using System.ServiceModel;
namespace DynamicsGPWebServiceSample
{
class Program
{
static void Main(string[] args)
{
CompanyKey companyKey;
Context context;
ListRestrictionOfNullableOfSalesTransactionState
transactionStateRestriction;
SalesOrderCriteria salesOrderCriteria;
SalesOrderSummary[] salesOrderSummary;
// 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 transaction state restriction object
transactionStateRestriction = new
ListRestrictionOfNullableOfSalesTransactionState();
transactionStateRestriction.EqualValue =
SalesTransactionState.History;
// Create a sales order criteria object
// Retrieve summary objects for historical sales orders
salesOrderCriteria = new SalesOrderCriteria();
salesOrderCriteria.TransactionState =
transactionStateRestriction;
// Specify the scope so that transactions for only the current
// user are retrieved
salesOrderCriteria.Scope =
SalesDocumentScope.ReturnBasedonSalespersonId;
try
{
// Retrieve the sales order summaries specified
salesOrderSummary =
wsDynamicsGP.GetSalesOrderList(salesOrderCriteria, context);
// Display the ID and amount of each summary object
StringBuilder summaryList = new StringBuilder();
foreach (SalesOrderSummary a in salesOrderSummary)
{
summaryList.AppendLine("Order number: " + a.Key.Id +
" Order amount: " + a.TotalAmount.Value.ToString("C"));
}
MessageBox.Show(summaryList.ToString());
}
catch (FaultException<System.ServiceModel.ExceptionDetail> ex)
{
MessageBox.Show(ex.Message);
}
}
}
}