Modules

filter

 

Objects/Functions

module (N/query)

SuiteScript 2.0

Query.createColumn(options)

{Query}.createColumn({fieldId: {string},formula: {string},type: {string},aggregate: {string},alias: {string},groupBy: ${7:boolean},label: ${8:string},context: {name: {0:string},params: {1:Object},params: {2:number},})

N/query Module
Query.createColumn()
Method Description: Creates a query result column based on the query.Query object. The query.Column object is the equivalent of the search.Column object in the N/search Module. The query.Column object describes the field types (columns) that are displayed from the query results. To create columns: Use Query.createColumn(options) to create columns on the initial query definition created with query.create(options). Use this method in one of two ways: Pass in an argument for the parameter options.fieldId. 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 Component.createColumn(options) to create conditions on the join relationships created with Query.autoJoin(options) and Component.autoJoin(options). Assign all created columns as array values to Query.columns. For an example, see Syntax. When you create a column, you can specify a field context. The field context determines how field values are displayed in the column. For example, you can specify that a column should display raw data (such as internal IDs), consolidated or converted amounts (such as currency totals), or user-friendly values (such as names). You can specify a field context in two ways: Use a context from the query.FieldContext enum directly as the value of the options.context parameter. For example: This example is the simplest way to specify a field context that does not accept additional parameters. Because the options.context parameter is an Object, this example is equivalent to the following: Use a context from the query.FieldContext enum as the value of the options.context.name parameter, and specify additional parameters using the options.context.params parameter. For example: In this example, the created column displays the value of the netamount currency field using the exchange rate that was in effect on January 1, 2019 for the currency with an ID of 4. In this release, only the query.FieldContext.CONVERTED context uses additional parameters. The supported parameters are currencyId and date. For the date parameter, you can pass a JavaScript Date object or query.RelativeDate object. If you pass a query.RelativeDate object using a value from the query.RelativeDateRange enum, use the start property or end property to specify the exact date of the exchange rate. For example, to use the exchange rate that was in effect at the beginning of the last fiscal quarter: If you use only the query.RelativeDate object from the query.RelativeDateRange enum and do not specify either the start or end properties, the end date of the relative date range is used. This behavior means that the following two date properties are equivalent: date: query.RelativeDateRange.LAST_FISCAL_QUARTER date: query.RelativeDateRange.LAST_FISCAL_QUARTER.end This method is a shortcut for the chained Query.root and Component.createColumn(options): Query.root.createColumn(options). The Query.root property references the root component, which is a query.Component object.
Returns: query.Column
Supported Script Types: Client and server scripts For more information, see SuiteScript 2.0 Script Types.
Governance: None
Module: N/query Module
Parent Object: query.Query
Sibling Object Members: Query Object Members
Since: 2018.1
Search NetSuite - https://system.netsuite.com/app/help/helpcenter.nl?search=Query.createColumn(options)

Example:

// Code Example 1
myTransactionLine.createColumn({
fieldId: 'netamount',
context: query.FieldContext.CURRENCY_CONSOLIDATED
});

// Code Example 2
myTransactionLine.createColumn({
fieldId: 'netamount',
context: {
name: query.FieldContext.CURRENCY_CONSOLIDATED
}
});

// Code Example 3
myTransactionLine.createColumn({
fieldId: 'netamount',
context: {
name: query.FieldContext.CONVERTED,
params: {
currencyId: 4,
date: new Date('2019/01/01')
}
}
});

// Code Example 4
myTransactionLine.createColumn({
fieldId: 'netamount',
context: {
name: query.FieldContext.CONVERTED,
params: {
currencyId: 4,
date: query.RelativeDateRange.LAST_FISCAL_QUARTER.start
}
}
});

// Code Example 5
// 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_1510780373.html