How to get record producer variable (answered questions label and answer) into description

attanhes
Tera Guru

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.

 

find_real_file.png

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?

1 ACCEPTED SOLUTION

attanhes
Tera Guru

Hi,

I just worked this out by creating a new before insert business rule in the incident table by adding above script.

find_real_file.png

 

 

View solution in original post

7 REPLIES 7

Allen Andreas
Administrator
Administrator

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!

Hi Alan,

 

Thanks for the response.

My requirement is to get only answered variables (questions labels and answers) into the description field.

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!

Thanks for the confirmation, let me try this.