Breakdown mapping script not setting values properly

SBratcher
Tera Expert

I am trying to create a dashboard widget that will show how many RITMs were submitted with each of the options specified in one of two variables.

 

I used the details from this older post to create my script, https://www.servicenow.com/community/platform-analytics-forum/how-to-create-breakdowns-on-catalog-va...

 

SBratcher_0-1670944627027.png

the gs.info output shows appropriate RITM numbers and topics and the scorecard for the indicator lists all of the available options, so the script is definitely getting the right data, but the indicator scores are all showing up in the catch-all "other" breakdown item rather than the appropriate topic.

 

Does anyone have any idea where I might have gone wrong? The only other scripted mapping I have written used buckets so this is a bit new.

13 REPLIES 13

Now that I thinking... you might have a mismatch between the actual display name and the sys_ids.

Replace getDisplayValue to getValue in your original script. 


If I helped you with your case, please click the Thumb Icon and mark as Correct.


That is how I had it first, it logs the name instead of the label, but it still doesn't attach them to the scores in PA. 

I truly think the problem is a mismatch between what the script provides when compared to the breakdown source (screen below). The breakdown source says field=sys ID...

 

SebastianDL_0-1671043601020.png

 

I would continue troubleshooting by typing question_choice.list on the left nav and filtering it with your conditions. Then copy the sys_id of one of them. That is exactly what the original script should return as one of the examples.

 

SebastianDL_1-1671043939213.png

 

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.


JosephW1
Tera Guru

I just got done successfully setting up this same concept in a breakdown for one of my customers and I can confirm the issue is as @Sebas Di Loreto mentioned, your mapping script needs to return a sys_id.

Here is the way I accomplished this in my script. Notice that, instead of returning a gr.variables.someField's value, it takes that value and queries question_choice table to find the corresponding entry in that table and return its sys_id instead.

 

Some considerations:

1. Since your concept conditionally utilizes one of two variables, you'd have to conditionally change the questionSysId that you utilize in my script.

2. If any of the values are freeform and don't exist as question_choices then this will not work for those values.

 

(function executeScript() {
	// Get Unrestricted GR
	var gr = new GlideRecord('sc_task');
	if (gr.get(current.sys_id)) {
		
		// Get Utilized Question Choice Sys ID
		var questionSysId = '916de0aa1b78d9507b16ea04bc4bcb78'; //License Type
		var questionChoice = new GlideRecord('question_choice');
		questionChoice.addQuery('question', '=', questionSysId);
		questionChoice.addQuery('value',    '=', gr.variables.license_type);
		questionChoice.query();
		if (questionChoice.next()) {
			return questionChoice.sys_id; //found corresponding selected choice
		}
		return ''; //failed to find corresponding selected choice
	}
	return ''; //failed to find sc_task
})();