Breakdown script question

Blair5
Tera Guru

I have a breakdown script that is getting the a list of users, displaying the user name and their user ID. I want to display it by a different field stored on the user table. However, the breakdown continues to show it as the full name. The breakdown mapping for this script is using the other field. Any ideas why this wouldn't work? Thanks.

var users= [];

var manager = current.taskslatable_team.manager.getRefRecord();

if (manager != null && manager.u_include == true) {
         users.push(manager.getValue('u_name'));
} 

users;
1 ACCEPTED SOLUTION

Josh Cooper
ServiceNow Employee
ServiceNow Employee

I wrote a long lovely post on this and the new Community system lost it when I went to get the link at the end. 😛  My apologies.

If you're just trying to change the Display value for the breakdowns, the way Automated Breakdowns works, you're stuck with the display value for the table.  So you've got two possibilities:

 

1.  Change the display value for the sys_user table.  Usually you can't do this, because it impacts every other table in the system, and potentially some integrations as well if they depend on the Display Value.  It's worth investigating though if the Assigned To field on the tickets for example isn't useful and you'd rather have this other value instead, but test thoroughly!

 

2.  A scripted breakdown or "Breakdown Sandwich".  We generally don't recommend them because of the complexity and potential overhead, but in some cases it's the only way to meet the business objective.  Mainly it's used in situations where the thing you want to breakdown by isn't a Choice or Reference field, but the way it operates has the byproduct of allowing you to choose the Display field you want to use.  The way it works is you're building a manual breakdown, which you then populate using a scheduled job.  The values you put into the manual breakdowns in that table become your Display values.  Then you build a Breakdown Source against pa_manual_breakdowns where the Breakdown = (the manual breakdown you just built) and an Automated Breakdown against that.  The Breakdown Mapping will use a script, so that it can take the current user value in your case, and find the pa_manual_breakdown with the value you want to match, and return that sys_id.  Now the sys_id refers to a table where the Display value is the one you set.

Here's more information on that:

https://community.servicenow.com/community?id=community_question&sys_id=7dd0cf65db98dbc01dcaf3231f96194d

View solution in original post

17 REPLIES 17

Hi Adam,

If a manager is a manager (or manager's manager...) of a team, I want to show the number of SLAs the teams under those managers achieved/breached. I have that working just fine but I need to user a different field (u_name) to display on the breakdown widget.

Will try what you suggested.

Adam Stout
ServiceNow Employee
ServiceNow Employee

1) You want a hierarchy rollup.  Come to the PA301 Lab at K18.  We go over how to do this.

2) The breakdown script MUST return a sys_id.  That is what is stored in the scores table.  The sys_id is translated into text via the breakdown source's display name.

Thanks Adam. Unfortunately I am not attending K18 😞 

Any documentation I can reference for the hierarchical breakdown? Also, we ran into a known PRB when trying to do a breakdown by a 'dot.walked' field, which is fixed in a future release.

Adam Stout
ServiceNow Employee
ServiceNow Employee

You are missing out.  Lots of great stuff (especially for PA and Reporting) at Knowledge.

What PRB did you hit?  I'm not aware of dot walking problem with breakdowns.

I believe we may be posting some documentation for hierarchy rollups after knowledge based on the changes we are making.  However, here is a function I use to roll up through n-levels of hierarchy.

var getHierarchy = function (seedElement, parentField, tableName)
{
    var hierarchy = [];
    var loops = 0;
    var maxLevels = 10;
    var origSeed = seedElement;
    while (seedElement) {
        hierarchy.push(seedElement.toString());
        var gr = new GlideRecord(tableName);
        gr.addQuery('sys_id', '=', seedElement);
        gr.query();
        if(gr.next())
        {
            seedElement = gr.getValue(parentField);
        } else {
            seedElement = null; // this shouldn't happen, but handle it if it does
        }
        // break if we have a loop in the hierarchy (a.k.a., the Dan rule)
        if(new ArrayUtil().contains(hierarchy, seedElement))
        {
            break;
        }
        // break if we ever find a parent pointing to itself (a.k.a., the Heath rule)
        if(gr.getValue(parentField) == gr.getValue('sys_id'))
        {
            break;
        }
        // break id we exceed a reasonable number of levels (a.k.a., the Arnoud rule)
        if(++loops >= maxLevels)
        {
            this._warning('Max Levels (' + maxLevels + ') exceed for table: ' + tableName + ' with seed value: ' + origSeed);
            break;
        }
    }
    return hierarchy;
};

getHierarchy(current.assigned_to, 'manager', 'sys_user');

Be sure to test this to make sure this gets you what you need. This returns an array of sys_ids for sys_user which your breakdown would be based on.

Hi Adam!

 

Can you help me? Where should this script live? Would it be in the mapping of the breakdown?

 

Thanks.

Regards,

Kauê.