Data Visualization - Pivot table dynamic group by

Kyle Pasmore
Tera Contributor

Hi,

I have a pivot table data visualization and I want to be able to dynamically change the column group by using a dropdown.

 

I believe that I should be able to script the group by section of the data visualization but I cannot find any documentation on that this code should look like. 

 

I need to have the row's grouped by 'assignment_group' and 'assigned_to' and have the column dynamic.

 

Could someone provide an example of what this code should look like or a link to some documentation I have missed that will explain what functions are accepted and what the expected returned values are.

3 REPLIES 3

Kyle Pasmore
Tera Contributor

I have since found this doumentation that show in the typedefs section that the format need to be in somekind of array for groupBy but I'm still unsure how this should be formatted

https://developer.servicenow.com/dev.do#!/reference/next-experience/utah/shared-components/sn-par-vi...

Jakub_Popielarz
Tera Contributor

I know it's an old topic, but this may be of some use to somebody:

The Group by (at least in case of data visualizations based on Indicators) needs to have the following structure:

[
    {
        "groupBy": [
            {
                "dataSource": "aW5kaWNhdG9yNjVkM2E3ZDBjM2Q2ODI1MDNjMTI0ZTBhZDAwMTMxMmExNzE2MjkzODM0NTg4",
                "groupByField": "22ad97edc31282103c124e0ad00131d5"
            }
        ],
        "maxNumberOfGroups": "ALL"
    }
]

 As far as I know that's the minimum required.

  • The `dataSource` needs to be fileld in, otherwise the group by will not be actually applied. The value there is the same as api.element.<id of data visualization>.dataSources[<index>].id Data visualizations can have multiple dataSources, but if you have only one the index will always be 0.
  • The `groupByField` can be either empty - then no Group By will be applied, or set to the sys ID of an indicator you want to group by
  • The `maxNumberOfGroups` is not actually required, but it can be set to either a number or "ALL", as in my example. As far as I know that's the only way you can overwrite the default max of 10 groups displayed.

nandinijain
Tera Contributor

@Kyle Pasmore Did you get solution for this? I have similar requirement. Tried below script for dynamically binding groupBy but its not working.

const groupByConfig = [{
"groupBy": [{
"dataSource": api.elements.pivot_table_1.dataSources[0].id,
"groupByField": "status",
"isRange": false,
"isChoice": false,
"isPaBucket": false
}],
"maxNumberOfGroups": "ALL",
"numberOfGroupsBasedOn": "NO_OF_GROUP_BASED_ON_PER_METRIC",
},
{
"groupBy": [{
"dataSource": api.elements.pivot_table_1.dataSources[0].id,
"groupByField": selectedColumnGroup,
"isRange": false,
"isChoice": false,
"isPaBucket": false
}],
"maxNumberOfGroups": "ALL",
"numberOfGroupsBasedOn": "NO_OF_GROUP_BASED_ON_PER_METRIC",
}
];