Class: Fetch

Fetch

Provides properties and methods to create FetchXml queries


new Fetch(entityName, attr, filterConditions)

Default Constructor

Parameters:
Name Type Description
entityName string

Optional. Name of the entity which the query is for

attr string | boolean | Array.<string>

Optional. Either a column name, or a list of column names, or a boolean value indicating that all the attribute values want to be retrieved. The default value is null, and means that only the primary attribute will be retrieved.

filterConditions object

Optional. Object that describes conditions in an JSON notation. More Info: Fetch#setFilter

Source:
Examples

Create an empty FetchXml

var fetch = new Fetch();
console.log(fetch.toString()); // outputs: <fetch><entity></entity></fetch>

Create a Fetch query for the "account"" entity, with 3 attributes and one filter

var fetch = new Fetch("account",["description","createdon","ownerid"],{name:"acme"});

Create a Fetch query for the "account"" entity, with all attributes and one filter

var fetch = new Fetch("account",true,{name:"acme"});

Methods


setFilter(filterCondition)

Sets the filter criteria of the current FetchXml with the specified values.

The specified value can be eiher a Filter object or a conditions object.

A conditions object is a Javascript object where every property represents a condition.

If the object contains a property, and that property contains a simple value, like an string or a number, that means property equals to value.

If you need to specify another operator, then you have to use the form: {attribute:{$operator:value}}

If the value is an array, then the $in operator is used.

If the value is a null value, then the nulloperator is applied. For example: {name:null} will retrieve all the records where the name is null.

Parameters:
Name Type Description
filterCondition Filter | object

A Filter object or a Conditions specified in JSON notation.

Source:
See:
Examples

When the simple syntax is used {name:value} then the $eq operator is used. The following filter retrieves all records where the attribute name is equals to "myAccount"

var cond = {name:"myAccount"};

The following retrieves all records where the attribute name is equals to "myAccount" AND the createdon date is equals to the system date

var cond = {name:"myAccount", createdon:new Date()}

If you need to specify additional operators, then use a subobject with the operator name. The following retrieves all records where the attribute name begins with "contoso%" and the attribute createdon is bigger than the current date

var cond = {name:{$like:"contoso%"}, createdon:{$bt:new Date()}}

Currently supported operators:

$eq, $neq, $gt, $ge, $le, $lt, $like, $notlLike, $in, $notIn, $between, $notBetween

If the value is an array, then the in operator is applied. The wollowing means: where name is one of contoso, acme or cycleworks

var cond = {name:["contoso", "acme", "cycleworks"]};

To specify the null operator, use a null value next to the attribute name. The following will retrieve all the records where the name is null.

var cond = {name:null};

To specify the Not Null operator, use a the "$notNull" value next to the attribute name. The following will retrieve all the records where the name is Not null.

var cond = {name:"$notNull"};