Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Aggregates in the now experience framework( ui builder ) . need help!!

KhushbooA
ServiceNow Employee
ServiceNow Employee

We currently have a Customer Health table containing data at a granular level — Account NumberBusiness Unit (BU), and Opportunity. The requirement is to display this data in a record list view where each Account appears only once, with all corresponding metrics aggregated (using functions like SUM, MIN, MAX, etc.) at the Account level. 

Additionally, there are interactive filters (such as Opportunity Stage: Open / Closed) that should be applied prior to aggregation — meaning the dataset should first be filtered based on user selection, and only then should the aggregations be computed dynamically to reflect the filtered context. 

Example 

  • Metric: NNACV 
  • Requirement: Display NNACV as the sum of all opportunity-level NNACV values for each Account. 
  • Filter Behaviour: If the user selects Opportunity Stage = Open, then only opportunities with stage Open should be considered in the sum aggregation. 

    Example: Have attached a file.
    Code Written: 
    var ga = new GlideAggregate(sourceTable); 
    if (filter) { 
        ga.addEncodedQuery(filter); 
    } 
    ga.addAggregate('SUM', 'nnacv'); // sum nnacv 
    ga.addAggregate('MAX', 'next_renewal_date'); /// max next renewal date 
    ga.addAggregate(‘MAX’, 'cacv'); //max cacv 
    ga.addAggregate('SUM', 'renewal_acv'); //sum renewal acv 
    ga.addAggregate('MAX','quarter'); // max dynamic quarter 
    ga.groupBy('account_number'); 
    ga.query(); 
     
    var updatedAccounts = []; 
     
    while (ga.next()) { 
        var acct = ga.getValue('account_number'); 
        var sumNnacv = ga.getAggregate('SUM', 'nnacv'); 
        var nxtRenewal = ga.getAggregate('MAX', 'renewal_date'); 
     var acctcacv = ga.getAggregate('SUM', 'cacv'); 
     var renewalacv = ga.getAggregate('SUM', 'renewal_acv'); 
     var forecasted_downsell_quarter = ga.getAggregate('MAX','quarter') ;
    gs.info(--- print everything ---)
    
    /* can be added to the advanced script option of the presentational list */
    }
    /*
    Runtime: ~3 mins
    
    Apply the filter at the source level (Account BU Opportunity) and aggregate the data to display the table at the Account level." */
      

    Is there any optimised approach to perform aggregation in the Servicenow platform to showcase aggregated values in the List view when your source data and filters are applied at different level??

    Suggestions will be really helpful? 

0 REPLIES 0