query.create(options)
Method Description |
Creates a query.Query object. Use this method to create your initial query definition. The initial query definition uses one query type. For available query types, see query.Type. After you create the initial query definition, use Query.autoJoin(options) to create your first join. Then use Query.autoJoin(options) or Component.autoJoin(options) to create all subsequent joins. For standard record types, the query type that you specify is validated immediately and must be one of the values in the query.Type enum. For custom record types, the query type that you specify is not validated until the query is executed using Query.run() or Query.runPaged() (or using the promise versions of these methods). If you specify a query type for a custom record type that does not exist, this method allows you to create the query and does not throw an error. However, when you perform the query, an error is thrown.
Important:
The N/query module lets you create and run queries using the SuiteAnalytics Workbook query process. You can use the N/query module to load and delete existing queries, but you cannot save queries. You can save queries using the SuiteAnalytics Workbook interface. For more information, see Navigating SuiteAnalytics Workbook. For more information about creating queries, see Scripting with the N/query Module. |
Returns |
|
Supported Script Types |
Client and server scripts For more information, see SuiteScript 2.x Script Types. |
Governance |
None |
Module |
|
Sibling Module Members |
|
Since |
2018.1 |
Parameters
The options
parameter is a JavaScript object.
Parameter |
Type |
Required / Optional |
Description |
---|---|---|---|
|
string |
required |
The query type that you want to use for the initial query definition. Use the query.Type enum to set this value (for an example, see Syntax). When you perform
Important:
The N/query module supports the same record types that are supported by the SuiteAnalytics Workbook interface. For more information, see Available Record Types. |
|
Object[] |
optional |
An of objects to be used as query columns. If you specify a value for this parameter, the Query.createColumn(options) method is called on each object in the.
Important:
You must include a query.Column object in your query definition to avoid scripting errors. This object is an optional parameter with the query.create(options) method, but at least one Column must be created for every query definition. For more information, see the syntax example below. |
|
Object |
optional |
A condition for the query. If you specify a value for this parameter, the Query.createCondition(options) method is called on the object you specify. |
|
Object[] |
optional |
An of objects representing sort options. If you specify a value for this parameter, the Query.createColumn(options) and Query.createSort(options) methods are called on each object in the . |
Errors
Error Code |
Thrown If |
---|---|
|
The specified query type is invalid.
Note:
This error is not thrown if you specify a custom record type as the query type. Custom record types are validated when the query is executed using Query.run() or Query.runPaged() (or using the promise versions of these methods). |
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'
});
myCustomerQuery.columns = [
myCustomerQuery.createColumn({
fieldId: 'entityid'
}),
myCustomerQuery.createColumn({
fieldId: 'id'
}),
mySalesRepJoin.createColumn({
fieldId: 'entityid'
}),
mySalesRepJoin.createColumn({
fieldId: 'email'
}),
mySalesRepJoin.createColumn({
fieldId: 'hiredate'
})
];
myCustomerQuery.sort = [
myCustomerQuery.createSort({
column: myCustomerQuery.columns[1]
}),
mySalesRepJoin.createSort({
column: mySalesRepJoin.columns[0], ascending: false
})
];
var resultSet = myCustomerQuery.run();
...
// Add additional code