<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Insert variables into incident description in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/insert-variables-into-incident-description/m-p/1384297#M41223</link>
    <description>&lt;P&gt;You can loop through all the check boxes with a condition inside the loop to check if the check box is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var checkBoxVariables = [];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;checkBoxVariables[0] = 'check_box_variable_1';&lt;/P&gt;
&lt;P&gt;checkBoxVariables[1] = 'check_box_variable_2';&lt;/P&gt;
&lt;P&gt;checkBoxVariables[2] = 'check_box_variable_3';&lt;/P&gt;
&lt;P&gt;checkBoxVariables[3] = 'check_box_variable_4';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var checkBoxLabels = [];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;checkBoxLabels[0] = 'check_box_label_1';&lt;/P&gt;
&lt;P&gt;checkBoxLabels[1] = 'check_box_label_2';&lt;/P&gt;
&lt;P&gt;checkBoxLabels[2] = 'check_box_label_3';&lt;/P&gt;
&lt;P&gt;checkBoxLabels[3] = 'check_box_label_4';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for(var i=0; i&amp;lt;checkBoxVariables.length; i++) {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(producer[checkBoxVariables[i]] == 'true') {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; current.description += '\n' + checkBoxLabels[i];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please mark helpful/correct if this has helped you.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Logan&lt;/P&gt;</description>
    <pubDate>Mon, 21 Feb 2022 21:38:09 GMT</pubDate>
    <dc:creator>Logan Poynter</dc:creator>
    <dc:date>2022-02-21T21:38:09Z</dc:date>
    <item>
      <title>Insert variables into incident description</title>
      <link>https://www.servicenow.com/community/developer-forum/insert-variables-into-incident-description/m-p/1384296#M41222</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I've got a record producer that creates incident records and I want the variables to display in the ticket description. All good so far, but I don't know how to display the choices when the question is a label type and the answer is a checkbox type value (could be multiple choices). Could someone please help with his, bare in mind I am very new to ServiceNow.&lt;/P&gt;
&lt;P&gt;We have this script include:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var addVariableToDescription = function (current, wizardVariable, descriptionText, options) {
    options = options ? options : {};
    var fieldName = options.fieldName ? options.fieldName : 'description';
    var str;
    // If the variable passed in was a reference, then use the value of refField from the record it points to.
    if (options.refField &amp;amp;&amp;amp; wizardVariable[options.refField]) {
        str = wizardVariable[options.refField].toString();
    } else {
        str = wizardVariable.toString();
    }
    if (str == 'true') {
        if (options.dontConvertTrue) {
            str = ' ';
        } else {
            str = 'Yes';
        }
    }
    if (options.convertFalse === true &amp;amp;&amp;amp; str == 'false') {
        str = 'No';
    }
    str = str == 'false' ? false : str;

    if (str) {
        // If a bookingDate option was provided, then reformat the string
        if (options.bookingDate) {
            str = wizardVariable.getDisplayValue() + ' on ' + options.bookingDate;
        }
        if (options.convertDate) {
            str = wizardVariable.getDisplayValue();
        }
        if (options.prepend) {
            current[fieldName] = descriptionText + str + '\n' + current[fieldName];
        } else {
            current[fieldName] += '\n' + descriptionText + str;
        }
    }
};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And this is what I've done so far in the record producer script: &lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;addVariableToDescription(current, producer.department, "\nDepartment: "); //this works fine, the type is multiple choice and displays the value selected

addVariableToDescription(current, producer.reason_for_request, "\nReason for request: "); //type of this is label and the choices are checkbox - multiple choice. I want this to display the value(s) selected but the way it is written now, it only displays 'Yes'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Feb 2022 21:14:05 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/insert-variables-into-incident-description/m-p/1384296#M41222</guid>
      <dc:creator>Amelie G</dc:creator>
      <dc:date>2022-02-21T21:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Insert variables into incident description</title>
      <link>https://www.servicenow.com/community/developer-forum/insert-variables-into-incident-description/m-p/1384297#M41223</link>
      <description>&lt;P&gt;You can loop through all the check boxes with a condition inside the loop to check if the check box is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var checkBoxVariables = [];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;checkBoxVariables[0] = 'check_box_variable_1';&lt;/P&gt;
&lt;P&gt;checkBoxVariables[1] = 'check_box_variable_2';&lt;/P&gt;
&lt;P&gt;checkBoxVariables[2] = 'check_box_variable_3';&lt;/P&gt;
&lt;P&gt;checkBoxVariables[3] = 'check_box_variable_4';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var checkBoxLabels = [];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;checkBoxLabels[0] = 'check_box_label_1';&lt;/P&gt;
&lt;P&gt;checkBoxLabels[1] = 'check_box_label_2';&lt;/P&gt;
&lt;P&gt;checkBoxLabels[2] = 'check_box_label_3';&lt;/P&gt;
&lt;P&gt;checkBoxLabels[3] = 'check_box_label_4';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for(var i=0; i&amp;lt;checkBoxVariables.length; i++) {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(producer[checkBoxVariables[i]] == 'true') {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; current.description += '\n' + checkBoxLabels[i];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please mark helpful/correct if this has helped you.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Logan&lt;/P&gt;</description>
      <pubDate>Mon, 21 Feb 2022 21:38:09 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/insert-variables-into-incident-description/m-p/1384297#M41223</guid>
      <dc:creator>Logan Poynter</dc:creator>
      <dc:date>2022-02-21T21:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Insert variables into incident description</title>
      <link>https://www.servicenow.com/community/developer-forum/insert-variables-into-incident-description/m-p/1384298#M41224</link>
      <description>&lt;P&gt;Hi Logan,&lt;/P&gt;
&lt;P&gt;I've tried producer.reason_for_request.getDisplayValue() but not only it didn't display the selected choice, it didn't display the question either, it just skipped it basically as I could only see the one for Department.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Feb 2022 21:48:09 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/insert-variables-into-incident-description/m-p/1384298#M41224</guid>
      <dc:creator>Amelie G</dc:creator>
      <dc:date>2022-02-21T21:48:09Z</dc:date>
    </item>
  </channel>
</rss>

