Component.createCondition(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Creates a condition (query filter) based on the query.Component 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:

  • Use Component.createCondition(options) to create conditions on the join relationships created with Query.autoJoin(options) and Component.autoJoin(options). Use this method in one of two ways:

    • Pass in arguments for the parameters options.fieldId, options.operator, and options.values. The combination of these arguments translates to <filter column><operator><field value> (for example, ‘city’ equals ‘Boston’).

    • Pass in an argument for the parameter options.formula. If you use this option, you can also use the optional parameter options.type.

  • If needed, use Query.createCondition(options) to create conditions on the initial query definition created with query.create(options).

  • If you have multiple conditions, use them to create a new nested condition with the methods Query.and(conditions), Query.or(conditions), and Query.not(condition).

  • Assign your simple or nested condition to Query.condition. For an example, see Syntax.

Returns

query.Condition

Supported Script Types

Client and server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/query Module

Parent Object

query.Component

Sibling Object Members

Component Object Members

Since

2018.1

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.fieldId

string

required if options.operator and options.values are used

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.

options.operator

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.

options.values

string[] | number[] | boolean[] | Date[] | query.RelativeDate[] | query.Period[]

required if options.fieldId and options.operator are used, and options.operator does not have a value of query.Operator.EMPTY or query.Operator.EMPTY_NOT

An array of values to use for the condition. This value sets the Condition.values property.

options.formula

string

required if options.fieldId is not used

The formula used to create the condition. This value sets the Condition.formula property.

For more information about formulas, see Formulas in Search and SQL Expressions.

options.type

string

required if options.formula is used

If you use the options.formula parameter, use this parameter to explicitly define the formula’s return type. This value sets the Condition.type property.

Use the appropriate query.ReturnType enum value to pass in your argument. This enum holds all the supported values for this parameter.

options.aggregate

string

optional

An aggregate function to run on the 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.

Syntax

Important:

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 firstCondition = myCustomerQuery.createCondition({ fieldId: 'id', operator: query.Operator.EQUAL, values: 107
});
var secondCondition = myCustomerQuery.createCondition({ fieldId: 'id', operator: query.Operator.EQUAL, values: 2647
});
var thirdCondition = mySalesRepJoin.createCondition({ fieldId: 'email', operator: query.Operator.START_WITH_NOT, values: 'foo'
}); myCustomerQuery.condition = myCustomerQuery.and( thirdCondition, myCustomerQuery.not( myCustomerQuery.or(firstCondition, secondCondition) )
); var resultSet = search.run();
...
// Add additional code 

          

Related Topics

query.Query
N/query Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices