Modules

filter

 

Objects/Functions

module (N/query)

SuiteScript 2.0

query.create(options)

{query}.create({type: {string*},columns: {Object[]},condition: {Object},sort: {Object[]}})

N/query Module
query.create()
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 execute the query, an error is thrown. The N/query module lets you create and run queries using the SuiteAnalytics Workbook query engine. 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: query.Query
Supported Script Types: Client and server scripts For more information, see SuiteScript 2.0 Script Types.
Governance: None
Module: N/query Module
Sibling Module Members: N/query Module Members
Since: 2018.1
Search NetSuite - https://system.netsuite.com/app/help/helpcenter.nl?search=query.create(options)

Example:

// Code Example 1
// 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

//SOURCE: https://system.netsuite.com/app/help/helpcenter.nl?fid=section_1510275581.html