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

I do not see any issue in your code, but was thinking if the custom field name is taskslatable_team, shouldn't this be start with u_

 

var users= [];
var manager = current.u_taskslatable_team.manager.getRefRecord();
if (manager != null && manager.u_include == true) {
users.push(manager.getValue('u_name'));
}
gs.print(users);

 

which table this field (u_taskslatable_team) is pointing to?

Hi Shishir,

 

Was changing the names of our fields because I'm not 100% sure on policy to post internal code.

Adam Stout
ServiceNow Employee
ServiceNow Employee

The script has to result in a sys_id that can be found int eh breakdown source.  You cannot break down by arbitrary strings.  They have to be in the breakdown source (looked up by sys_id).  I'm not sure what you are sending as script fields, but you have to fully qualify everything, you cannot use reference fields that are not passed.

I'm not actually sure what you are going for.  You are initializing array but are only allowing one value in your code.

Try this:

var user = null;
if (current.taskslatable_team.manager != null && current.taskslatable_team.manager.u_include == true) 
{ 
    user = current.taskslatable_team.manager;
} 
user;

 

Make sure you are sending the fields for manager and u_include to the script.

Adam,

See screenshot of the full script (back end field names changed for sec purposes). The breakdown source is looking by sys id.

find_real_file.png

Adam Stout
ServiceNow Employee
ServiceNow Employee

What are you trying to get from this?  You should be able to do this with a hierarchy query that will handle n levels of management.  

 

This might work but you are overthinking it.  The manager field is a sys_id.  Just push manager1, manager2, manager3 into the array.

 

var manager3 = current.xxxx.manager.manager.manager;
var manager3include = current.xxxx.manager.manager.manager.u_include;

if (manager3 != null && manager3include == true) 
{ 
    users.push(manager3);
} 

users;