Report: How to display Survey Question/Responses in columns.

Community Alums
Not applicable

I am trying to build a report having survey questions/responses in columns. I need the columns to show Question 1, Question 2, Question 3, Question 4, Question 5 and all the answers in a single row. How can I do this?

1 ACCEPTED SOLUTION

Community Alums
Not applicable

current.state means the business rule is running on the "asmt_metric_result" table, that has the state field. Customize your form layout to find the state field.

Sorry, I don't have gr.state in my script. It was in yours. This been a while so I was lost. Here is my working script. Please cleanup your script.

Business Rule:

find_real_file.png 

Condition: current.metric_type.getDisplayValue()=='Satisfactory Survey' && current.state == 'complete'

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('u_satisfactory_survey_response');
	gr.addQuery('u_survey_instance', current.sys_id);
	gr.query();
	if (!gr.next()){
		gr.initialize();
	}
		
	gr.u_survey_instance = current.sys_id;
	gr.u_metric_type = current.metric_type;
	gr.u_assigned_to =  current.user;
	gr.u_incident_number = current.trigger_id;
	gr.u_incident_assigned_to = current.related_id_1;
	gr.u_incident_assignment_group = current.related_id_2;
	
	var result = new GlideRecord('asmt_metric_result');
	result.addQuery('instance', current.sys_id);
	result.query();
	while(result.next()){
		if(result.metric == 'edfeec4f373ea20009dc65e2b3990ed4'){ //1
			gr.u_question_1 = result.metric;
			gr.u_string_value_1 = result.string_value;
			gr.u_normalized_value_1 = result.normalized_value;
			gr.u_nps_value_1 = result.nps_value;
		}
		if(result.metric == 'a1feec4f373ea20009dc65e2b3990ed5'){ //2
			gr.u_question_2 = result.metric;
			gr.u_string_value_2 = result.string_value;
			gr.u_normalized_value_2 = result.normalized_value;
			gr.u_nps_value_2 = result.nps_value;
		}
		if(result.metric == 'e1feec4f373ea20009dc65e2b3990ed5'){ //3
			gr.u_question_3 = result.metric;
			gr.u_string_value_3 = result.string_value;
			gr.u_normalized_value_3 = result.normalized_value;
			gr.u_nps_value_3 = result.nps_value;
		}
		if(result.metric == '25feec4f373ea20009dc65e2b3990ed5'){ //4
			gr.u_question_4 = result.metric;
			gr.u_string_value_4 = result.string_value;
			gr.u_normalized_value_4 = result.normalized_value;
			gr.u_nps_value_4 = result.nps_value;
		}			
		if(result.metric == '65feec4f373ea20009dc65e2b3990ed5'){ //5
			gr.u_question_5 = result.metric;
			gr.u_string_value_5 = result.string_value;
			gr.u_normalized_value_5 = result.normalized_value;
			gr.u_nps_value_5 = result.nps_value;
		}
	}	
	
	if (gr.isNewRecord()){
		gr.insert();
	}
	else {
		gr.update();
	}

})(current, previous);

View solution in original post

24 REPLIES 24

Hey Rajinis
Could you help us with the table (fields ) what all you have created, it would be of great help.

Please help me in details 
Step 1 : create new table 
Step 2 : Write business rule on this table correct ...

or what step by step explain 
Advance Thanks 

Community Alums
Not applicable

"asmt_metric_result"


Hopefully this will be the last question: Which table is the first GR running against? It looks like your custom table but that wouldn't make sense if the table is empty. I can see you're trying to initialize the table for data but why the query on the empty table (at least in my case)?


Community Alums
Not applicable

Thank you 🙂