Share via


Restriction reference

Several types of restrictions used with criteria objects. Some restriction types correspond to the various types of data, such as string values, integers, and booleans. Other restriction types are based on how the restriction is structured. For instance a "list" restriction specifies a collection of possible values for a property.

The restriction types are part of a hierarchy, with more complex restriction types being constructed from the simpler types. All restriction objects derive from the Restriction class in the Dynamics GP service.

Basic restrictions

The most basic restriction contains a single value of a specific type. These restrictions have a name with the form:

RestrictionOfNullableOf*Type*

 

Some restrictions of this type are for primitive types. For example the restriction RestrictionOfNullableOfInt32 represents a single integer value for the legacy endpoint. For the native endpoint, this restriction type is named RestrictionOfNullableOfint. Other restrictions of this type represent a single instance of a more complex piece of information. For instance, the restriction RestrictionOfNullableOfSalesDocumentType represents a single type of sales document.

The following C# example shows how to create and use a basic restriction for a criteria object. This example creates a boolean restriction for the IsOnHold property of the customer criteria object.

Cc508734.LegacyEndpoint(en-us,MSDN.10).gif** Legacy endpoint**

CustomerCriteria customerCriteria;
RestrictionOfNullableOfBoolean onHoldRestriction;

onHoldRestriction = new RestrictionOfNullableOfBoolean();
onHoldRestriction.EqualValue = true;
customerCriteria = new CustomerCriteria();
customerCriteria.IsOnHold = onHoldRestriction;

Cc508734.NativeEndpoint(en-us,MSDN.10).gif** Native endpoint **

CustomerCriteria customerCriteria;
RestrictionOfNullableOfboolean onHoldRestriction;

onHoldRestriction = new RestrictionOfNullableOfboolean();
onHoldRestriction.EqualValue = true;
customerCriteria = new CustomerCriteria();
customerCriteria.IsOnHold = onHoldRestriction;

List restrictions

The "list" restrictions specify a distinct set of values. These restrictions have a name with the form:

ListRestrictionOfNullableOf*Type*

 

Like the basic restrictions, some of these list restrictions are for primitive types and others for more complex types. List restrictions represent a distinct set of values of the specific types.

The following C# example shows how to create and use a list restriction for a criteria object. This example creates a list restriction for the Type property of the item criteria object. The restriction contains a list of two item types, for Service and SalesItem. Notice how an array is created that contains the two possible values for the list restriction.

ItemCriteria itemCriteria;
ListRestrictionOfNullableOfItemType typeRestriction;
ItemType?[] itemTypes;

typeRestriction = new ListRestrictionOfNullableOfItemType();
itemTypes = new ItemType?[2];
itemTypes[0] = ItemType.Service;
itemTypes[1] = ItemType.SalesItem;
typeRestriction.Items = itemTypes;
itemCriteria = new ItemCriteria();
itemCriteria.Type = typeRestriction;

Between restrictions

The "between" restrictions specify a range of values. You can specify a GreaterThan value, a LessThan value, or From and To values to specify a range. These restrictions have a name with the form:

BetweenRestrictionOfNullableOf*Type*

 

The between restrictions are available only for primitive types, like date/time or string values.

The following C# example shows how to create and use a between restriction for a criteria object. This example creates a between restriction for the Date property of a GL transaction criteria object. The property is set to a range between April 25, 2007 and April 26, 2007.

Cc508734.LegacyEndpoint(en-us,MSDN.10).gif** Legacy endpoint**

GLTransactionCriteria transactionCriteria;
BetweenRestrictionOfNullableOfDateTime dateRestriction;

dateRestriction = new BetweenRestrictionOfNullableOfDateTime();
DateTime startDate = new DateTime(2007, 4, 25);
DateTime endDate = new DateTime(2007, 4, 26);
dateRestriction.From = startDate;
dateRestriction.To = endDate;
transactionCriteria = new GLTransactionCriteria();
transactionCriteria.Date = dateRestriction;

Cc508734.NativeEndpoint(en-us,MSDN.10).gif** Native endpoint **

GLTransactionCriteria transactionCriteria;
BetweenRestrictionOfNullableOfdateTime dateRestriction;

dateRestriction = new BetweenRestrictionOfNullableOfdateTime();
DateTime startDate = new DateTime(2007, 4, 25);
DateTime endDate = new DateTime(2007, 4, 26);
dateRestriction.From = startDate;
dateRestriction.To = endDate;
transactionCriteria = new GLTransactionCriteria();
transactionCriteria.Date = dateRestriction;

Like restriction

String properties for criteria object have unique behavior. A "Like" expression, similar to those used in Transact-SQL can be used to define the restriction. The LikeRestrictionOfString restriction inherits from the "between" and "list" restriction types, so restrictions of this type can also be used as well.

The following C# example shows how to create and use a "Like" restriction for a string property of a criteria object. This example creates a restriction for the State property of the customer criteria object. Notice how the "Like" clause is used to specify customers from the state "ND".

Cc508734.LegacyEndpoint(en-us,MSDN.10).gif** Legacy endpoint**

CustomerCriteria customerCriteria;
LikeRestrictionOfString stateRestriction;

stateRestriction = new LikeRestrictionOfString();
stateRestriction.Like = "%ND%";
customerCriteria = new CustomerCriteria();
customerCriteria.State = stateRestriction;

Cc508734.NativeEndpoint(en-us,MSDN.10).gif** Native endpoint **

CustomerCriteria customerCriteria;
LikeRestrictionOfstring stateRestriction;

stateRestriction = new LikeRestrictionOfstring();
stateRestriction.Like = "%ND%";
customerCriteria = new CustomerCriteria();
customerCriteria.State = stateRestriction;