Performance Analytics BreakDown Mapping Script

vineetk_195
Tera Contributor

Hi All,

I am trying out with a breakdown mapping via script.

But unfortunately when I run my job I do not get any scores for my breakdown, although it works fine if I directly select field and not the script.

Any suggestion would be appreciated.

Thank you

Vineet

10 REPLIES 10

Josh Cooper
ServiceNow Employee
ServiceNow Employee

As long as you're coming up with a number, then you should be able to handle it with a breakdown script - like for example you could do something like:nt


getCount();



function getCount(){


        if(current.business_unit == 'Services'){


                        return 1;


        } else {


                            return 0;


      }


}


and that would work in theory.



If you had a number in a string field, then it'd just be something like:



getNumber();



function getNumber(){


      return Number(current.string_field);


}




If you're saying you had a business unit name as a string, then you'd just have to go find the sys_id of that business unit and return that, I BELIEVE that's what the breakdown script wants is the pa_breakdown associated to that ID:



getId();



function getId(){


      var gr = new GlideRecord('business_units_table');   //wherever that's stored


      gr.addQuery('name', current.<<business_unit_string_field>>);


      gr.query();



      if(gr.next()){


                return gr.sys_id;  


      }


}




If that doesn't work, you can do a seperate glide query to find the sys_id of the business unit breakdown in pa_manual_breakdowns.   OR it may just want the name rather than the ID - it takes some trial and error though.


thanks i will try the sum one!


Thanks Josh but a little elaboration if you can... say my bu's are <for example>



Corp


External


India



lets just use those for example and i want to be able to break down each of the records based on the bu.. how could i do that?


Josh Cooper
ServiceNow Employee
ServiceNow Employee

Ah, ok!   I think I understand now.



Ideally, you would want your Business Units to be in a Reference field pointing to some other table, or at least in a Choice list, so that you can control what values are selectable - either of those it's pretty easy to set up a new Breakdown on, and the Breakdown Wizard thing can do that for you automatically.



If that's not possible for whatever reason, then you'll need to do what's called a "Breakdown Sandwich", which lets you create your own breakdown for a string field based on all the values used so far.  



Detailed instructions for that are in Vince Loffeld's post here:



Re: How can I create a breakdown by task type on the Time Card table?



The basic gist is, you create a new manual breakdown, then build a scheduled job that runs every night, looks at the field you specify in the table you're interested in, and creates Breakdown entries for each one.



Then you create a new Breakdown Source, and use pa_manual_breakdown as your table source, (you're essentially using the first two steps to convert a string into a referenceable field so that you can create a Breakdown normally).



Then you just build the breakdown normally, but have to have the script that looks up the value for each record in the table so that it knows what actual Breakdown entry it belongs to.



That would give you basically your total count on the scorecard for the indicator, and then under Breakdowns you'd have "Business Unit" as an option, and under that, a count by day (or however the indicator is set) for each of the different Business Units



So you'd have like



100 total Incidents (for example) on the scorecard then


Breakdown:   Business Unit


                                                          40 - Corp


                                                          25 - External


                                                          35 - India


thanks we may end up using that.. the bottom line is BU is being imported as part of the user record and was not originally setup as a reference field to a table/choice list.. but was instead setup as a string field <HR had an issue with data normalization on bu's>  



however we have a real business need to develop reporting by bu's... so now we NEED to use it in performance analytics... we are really faced with three options...



1> change the field type   on the existing record and figure a method of back filling


        changing field types can be ugly... so we will have to toy with how to do this best.


2> create a new field and retire the old one


        this is problematic as BU is used   35 different times in a workflow instance so that is a lot of work just fixing those... not to mention catalog scripts and the import issues... so not really a good option


3> use some scripting method to get it broken down...



we are going to play with it to see how it works ...



OBTW... CLEVER trick for devs... ever wonder how many times something occurs in your workflows???



Create a new Database view <i called mine workflow activity to variables.


now for table one use   table sys_variable_value     order 100 variable prefix var where clause is blank


table two     wf_activity   order 200 prefix act where clause


var_document_key == act_sys_id



now go to the table in reporting and set workflow.version.published is true


and value is <what ever you want.. it can be string sid whatever>   in this case i used u_business_unit     and it spits out every activity with that value in a published workflow.....



a different use i get a LOT of is deactivating a group...   how do you KNOW which workflows use that group in the script or in an assignment group??



come to the table put in published is true ... value is sid of the group or name of the group.. and viola