- 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-28-2021 05:43 PM
Hi,
Please see this post for example: https://community.servicenow.com/community?id=community_question&sys_id=9df1cfa9db98dbc01dcaf3231f96...
You can check the value and if not null, then proceed to build concatenated field for that specific loop.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2021 06:02 PM
Hi Alan,
Thanks for the response.
My requirement is to get only answered variables (questions labels and answers) into the description field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2021 06:47 PM
Hi,
It's Allen, and yes, I saw that, which is why I said you could check the value and if not null, use it, otherwise, don't.
Please re-read my post.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2021 08:37 PM
Thanks for the confirmation, let me try this.