
- 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
‎11-11-2020 12:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2020 07:14 AM
Hi Rajinis,
I have done the same before changed result but it didnt work.
In the condition you mentioned current.state but in asmt_metric_result table there is no state field so can you please help me on this and also in business rule you used gr.state which is referring to your custom table so you have created state field over there.

- 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
‎11-13-2020 06:21 AM
Hi Rajinis,
Its working now. I have written business rule on asmt_metric_result table but now changed it to assessment instane which has state field.
Thanks for your support.
Regards,
Mahidhar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2020 12:06 PM
Cool.