Query.createColumn(options)
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:
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:
In this release, only the
If you use only the
Note:
This method is a shortcut for the chained Query.root and Component.createColumn(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 ID of the query result column. This value sets the Column.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 if |
The formula used to create the query result column. This value sets the Column.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 your query result column. An aggregate function performs a calculation on the column values and returns a single value. This value sets the Column.aggregate property. Use the appropriate query.Aggregate enum value to pass in your argument. This enum holds all the supported values for this parameter. |
|
string |
optional |
The alias for the column. An alias is an alternate name for a column, and the alias is used in mapped results. This value sets the Column.alias property. You must specify an alias in certain situations if you want to use ResultSet.asMappedResults() or Result.asMap(). For more information, see Column.alias. |
|
boolean |
optional |
Indicates whether the query results are grouped by this query result column. This value sets the Column.groupBy property. If you do not pass in an argument, the default value is set to |
|
string |
optional |
The label for the column. A label is important if the query object is used as the data source for printing (for example, in the TemplateRenderer.addQuery(options) method in the N/render module). |
|
Object |
optional |
The field context for values in the query result column. This value sets the Column.context property. If you do not pass in an argument, the default value is set to |
|
string |
required if |
The name of the field context. Use the appropriate query.FieldContext enum value to pass in your argument. This enum holds all the supported values for this parameter. |
|
Object |
required if |
The additional parameters to use with the specified field context. In this release, only the |
|
number |
required if |
The ID of the currency to convert to. |
|
required if |
The date to use for the exchange rate between the base currency and the currency to convert to. For example, if you want to use the exchange rate that was in effect on March 3, 2019, specify a query.RelativeDate object or JavaScript |
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