Query.createCondition(options)
Method Description |
Creates a condition (query filter) based on the query.Query object. A condition narrows the query results. The query.Condition object acts in the same capacity as the search.Filter object in the N/search Module. The primary difference is that query.Condition objects can contain other query.Condition objects. To create conditions:
Note:
This method is a shortcut for the chained Query.root and Component.createCondition(options): |
Returns |
|
Supported Script Types |
Client and server scripts For more information, see SuiteScript 2.x Script Types. |
Governance |
None |
Module |
|
Parent Object |
|
Sibling Object Members |
|
Since |
2018.1 |
Parameters
The options
parameter is a JavaScript object.
Parameter |
Type |
Required / Optional |
Description |
---|---|---|---|
|
string |
required if |
The field that the condition applies to. This value sets the Condition.fieldId property. Obtain this value from the Records Catalog. The Records Catalog lists every record type and field that is available using SuiteAnalytics Workbook and the N/query module. For more information, see Records Catalog Overview. |
|
string |
required |
The operator used by the condition. This value sets the Condition.operator parameter. Use the appropriate query.Operator enum value to pass in your argument. This enum holds all the supported values for this parameter. |
|
string[] | number[] | [] | Date[] | query.RelativeDate[] | query.Period[] |
required if |
An of values to use for the condition. This value sets the Condition.values property. |
|
string |
required if |
The formula used to create the condition. This value sets the Condition.formula property. For more information about formulas, see Formulas in Searches and SQL Expressions. |
|
string |
required if |
If you use the Use the appropriate query.ReturnType enum value to pass in your argument. This enum holds all the supported values for this parameter. |
|
string |
optional |
Use this parameter to run an aggregate function on a condition. An aggregate function performs a calculation on the condition values and returns a single value. This value sets the Condition.aggregate property. Use the appropriate query.Aggregate enum value to pass in your argument. This enum holds all the supported values for this parameter. |
|
boolean |
optional |
Use this parameter to specify the case of filtered text. This parameter is only valid for text fields. You may encounter script errors if this parameter is set with numbers or date values. You can use this parameter to improve the performance of the final query. By default, this value is set to |
Syntax
The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/query Module Script Samples.
// Add additional code
...
var myCustomerQuery = query.create({
type: query.Type.CUSTOMER
});
var mySalesRepJoin = myCustomerQuery.autoJoin({
fieldId: 'salesrep'
});
var myLocationJoin = mySalesRepJoin.autoJoin({
fieldId: 'location'
});
var myCondition = myCustomerQuery.createCondition({
fieldId: 'entityid',
operator: query.Operator.ANY_OF,
values: ['UK Cust USD','EU Cust'],
caseSensitive: true
});
myCustomerQuery.condition = myCustomerQuery.and(
myCondition
);
myCustomerQuery.columns = [
myCustomerQuery.createColumn({
fieldId: 'entityid'
}),
myCustomerQuery.createColumn({
fieldId: 'id'
}),
mySalesRepJoin.createColumn({
fieldId: 'entityid'
}),
mySalesRepJoin.createColumn({
fieldId: 'email'
}),
mySalesRepJoin.createColumn({
fieldId: 'hiredate'
}),
myLocationJoin.createColumn({
fieldId: 'name'
})
];
myCustomerQuery.sort = [
myCustomerQuery.createSort({
column: myCustomerQuery.columns[3]
}),
myCustomerQuery.createSort({
column: myCustomerQuery.columns[0],
ascending: false
})
];
var resultSet = myCustomerQuery.run()
...
// Add additional code