Styles

Note:

The content in this help topic applies to SuiteScript 2.x.

Styles let you change the format of cells in table views and pivots based on conditions that you specify. You can create standalone styles that format the color, font size, font style, and other attributes in a cell, and you can add these standalone styles to conditional formatting rules and report style rules (for pivots).

For more information about styles in SuiteAnalytics Workbook, see Conditional Formatting.

To create a standalone style, use workbook.createStyle(options). This method creates a workbook.Style object. You can provide the following optional parameters to workbook.createStyle(options):

          var myFirstStyle = workbook.createStyle({
    backgroundColor: workbook.createColor({
        red: 255,
        green: 192,
        blue: 203
    })
});

var mySecondStyle = workbook.createStyle({
    fontSize: workbook.FontSize.LARGE,
    fontStyle: workbook.FontStyle.ITALIC,
    fontWeight: workbook.FontWeight.BOLD
}); 

        

To create a report style, first use workbook.createReportStyleRule(options) to create report style rules, similar to creating conditional formatting rules for a conditional format. This method creates a workbook.ReportStyleRule object. When you use this method, you must provide the following parameters:

          var myReportStyleRule = workbook.createReportStyleRule({
    expression: workbook.createExpression({
        functionId: workbook.ExpressionType.COMPARE,
        parameters: {
            comparisonType: 'GREATER_OR_EQUAL',
            operand1: workbook.createExpression({
                functionId: workbook.ExpressionType.MEASURE_VALUE,
                parameters: {
                    measure: myCalculatedMeasure
                }
            }),
            operand2: workbook.createConstant(
                workbook.createCurrency({
                    amount: 1,
                    id: 'USD'
                })
            )
        }
    }),
    style: workbook.createStyle({
        backgroundColor: workbook.createColor({
            red: 255,
            green: 192,
            blue: 203
        })
    })
}); 

        

After you create a set of report style rules, use workbook.createReportStyle(options) to assemble the set of rules into a single workbook.ReportStyle object. In addition to the report style rules, you must provide a selector that selects the cell in the pivot to apply the style to. For more information, see Selectors.

          var conditionalRowSelector = workbook.DescendantOrSelfNodesSelector;
var conditionalColumnSelector = workbook.DescendantOrSelfNodesSelector;
var conditionalMeasureSelector = workbook.createMeasureSelector({
    measures: [myCalculatedMeasure]
});

var measureValueSelector = workbook.createMeasureValueSelector({
    rowSelector: conditionalRowSelector,
    columnSelector: conditionalColumnSelector,
    measureSelector: conditionalMeasureSelector
});

var myReportStyle = workbook.createReportStyle({
    selectors: [measureValueSelector],
    rules: [myFirstReportStyleRule, mySecondReportStyleRule]
}); 

        

Related Topics

Data Dimensions
Data Measures and Calculated Measures
Expressions
Pivot Axes
Selectors
Pivots

General Notices