Conditional Formatting Rules
The content in this help topic applies to SuiteScript 2.x.
Conditional formatting rules let you highlight workbook visualization results based on criteria that you define. For example, you can change a cell’s background color, font size, font style, and other attributes.
For more information about conditional formatting in SuiteAnalytics Workbook, see Conditional Formatting.
To create a conditional formatting rule, use workbook.createConditionalFormatRule(options). This method creates a workbook.ConditionalFormatRule object. When you use this method, you must provide the following parameters:
-
filter
– A filter indicating when the conditional formatting rule should be applied. Use workbook.createTableColumnFilter(options) to create this filter as a workbook.TableColumnFilter object. You create a filter using an operator and a set of values. Use operators (or their string equivalents) from the query.Operator enum. Values are specified based on the column the filter is used for and the operator used.var myFilter = workbook.createTableColumnFilter({ operator: query.Operator.ANY_OF, values: [myArrayOfValues] });
-
style
– The style to apply when the filter evaluates totrue
. Use workbook.createStyle(options) to create a style as a workbook.Style object. When you create a style, you can use supporting methods such as workbook.createColor(options) and workbook.createFontSize(options) to define the different attributes of a style. For more information, see Styles.var myStyle = workbook.createStyle({ backgroundColor: workbook.createColor({ red: 255, green: 255, blue: 0 }); });
Use both parameters to create a conditional formatting rule:
var myRule = workbook.createConditionalFormatRule({
filter: myFilter,
style: myStyle
});
After you create a set of conditional formatting rules, use workbook.createConditionalFormat(options) to assemble the set of rules into a single workbook.ConditionalFormat object:
var myConditionalFormat = workbook.createConditionalFormat({
rules: [myFirstRule, mySecondRule]
});
You can provide a workbook.ConditionalFormat object to workbook.createTableColumn(options) to apply the set of conditional formatting rules to a column. For more information, see Table Columns.
var myTableColumn = workbook.createTableColumn({
datasetColumnAlias: 'MyColumn',
conditionalFormats: [myFirstConditionalFormat, mySecondConditionalFormat]
});