- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2021 05:33 PM
Hi,
I have a record producer with 20 multiple-choice variable questions. I only need answered questions by concatenating answered with questions label and answered into the descriptions field only for those multiple-choice questions.
I tried the below script in record producer script to get only answered questions label and values but unfortunately, it is not working.
var gr = new GlideRecord('question_answer');
//gr.addQuery('table_sys_id', current.sys_id); //sys_id of record in question 5312acc4dbab34102721455215961993
gr.addQuery('table_sys_id', '85e5f5dcdbabf050691a7b53f39619af'); //sys_id of record in question 5312acc4dbab34102721455215961993 incident
gs.log("Current SysID " + current.getUniqueValue());
gr.query();
var comments = '';
while (gr.next()) {
if (gr.value && gr.question.type == 3) { //exclude questions with empty values
//if (gr.value) { //exclude questions with empty values
comments += gr.question.getDisplayValue() + ": " + gr.value.getDisplayValue() + "\n"; //display question and answer
}
}
current.comments = comments;
current.description = comments;
Can someone please help me to work this out?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2021 01:26 AM
Hi,
I just worked this out by creating a new before insert business rule in the incident table by adding above script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2021 12:09 AM
Hi Alan,
In which table I should write this before insert business rule? This record producer creates incident records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2021 01:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2021 01:15 PM
Hi,
I have further developed this script by adding more functions. Just adding my script into this thread in case it might be helpful for others.
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('question_answer');
gr.addQuery('table_sys_id', current.sys_id);
//gr.addQuery('table_sys_id', '85e5f5dcdbabf050691a7b53f39619af'); //sys_id of record in question 5312acc4dbab34102721455215961993 incident
//gs.log("Current SysID " + current.getUniqueValue());
gr.query();
var choice = '';
var descript = '';
var category = '';
while (gr.next()) {
//if (gr.value){//exclude questions with empty values
if (gr.value && gr.question.type == 3 && gr.question.name != "v_facilities_incident_category" )
//if (gr.value && gr.question.type != 6 && gr.question.type != 8 ) {
{
choice += gr.question.getDisplayValue() + " : " + "\n" + gr.value.getDisplayValue() + "\n"; //display question and answer
}
else if (gr.question.type == 2)
{
descript += gr.value.getDisplayValue() + "\n";
}
else if (gr.question.name == "v_facilities_incident_category")
{
category += gr.question.getDisplayValue() + " : "+ gr.value.getDisplayValue() + "\n";
}
}
current.description = "============== Category Type ============== " + "\n"+ category
+ "\n" + "============== Choices ==============" + "\n" + choice
+ "\n" + " ============== Description ==============" + "\n" + descript;
//current.comments = descript;
current.work_notes = "============== Category Type ============== " + "\n"+ category
+ "\n" + "============== Choices ==============" + "\n" + choice
+ "\n" + " ============== Description ==============" + "\n" + descript;
})(current, previous);
This script helps to print the details into description as in below format