- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2016 11:26 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2020 09:00 AM
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:
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2016 12:58 PM
We ended up creating a custom table that is updated every time an answer is saved. This was easier than the alternative which was a database view (we never tried to put a database view together because we needed some additional logic the custom table provided).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2016 02:01 PM
Yes you are right. Custom table is the easiest way. But need some inputs from you if it can be achieved by a database view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2016 02:31 PM
We did not pursue a view because we would essentially be doing joins repeatedly to get the data and it would not be as dynamic. So I cannot comment on the view, other than it may potentially work. Once we went with the custom table we never looked back - it was an easy option.
John's solution for a Pivot Table will work great if you have strictly numerical responses (or rather want to display your output as numerical choices). I seem to recall when we tried a Pivot Table we had responses that had output which was not very user friendly in a numeric fashion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 02:10 PM
I'm running in to the same issue. How did you design/build your table? Did you have to create a custom table for each survey or was it scripted in some way?