<?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: how to display value of variable having different data types like number,string,images,date &amp;amp in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2789950#M511511</link>
    <description>&lt;P&gt;thank you timi thats working fine and i have done similar changes only now its working fine .&lt;/P&gt;&lt;P&gt;now i have another qustion&amp;nbsp;&lt;/P&gt;&lt;P&gt;there is screen short captured in the answers , i wnt that to populate it on same RITM additional comments as a link so that whenever we click the link i want show a preview of that snippet to be viewed&amp;nbsp; how can we acheive this ,?&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jan 2024 02:48:41 GMT</pubDate>
    <dc:creator>chaitanyakumarD</dc:creator>
    <dc:date>2024-01-12T02:48:41Z</dc:date>
    <item>
      <title>how to display value of variable having different data types like number,string,images,date &amp;time et</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2781884#M510982</link>
      <description>&lt;DIV&gt;i triggered a survay once a RITM is closed and those answers i want to capture in additional comments but it is storing only backend values for answers . can any one&amp;nbsp; correctme in the code which i have written&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;(function executeRule(current, previous /*null when async*/ ) {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var assessmentResponses = [];&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var assessmentQuestionGR = new GlideRecord('asmt_assessment_instance_question');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; assessmentQuestionGR.addQuery('instance', current.sys_id);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; assessmentQuestionGR.addQuery('valueISNOTEMPTY');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; assessmentQuestionGR.query();&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; while (assessmentQuestionGR.next()) {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var question = assessmentQuestionGR.metric.getDisplayValue(); // Use getDisplayValue() for reference fields&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var answer = assessmentQuestionGR.value.toString(); // Replace 'value' with the actual field name for the answer&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assessmentResponses.push({&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; question: question,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; answer:&amp;nbsp; answer&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; // Update RITM Additional Comments with assessment responses&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var ritm = new GlideRecord('sc_req_item');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; if (ritm.get('sys_id', current.task_id)) {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var additionalComments = "\nAssessment Responses:\n";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var i = 0; i &amp;lt; assessmentResponses.length; i++) {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; additionalComments += assessmentResponses[i].question + ': ' + assessmentResponses[i].answer + '\n';&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ritm.comments += additionalComments;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ritm.update();&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;})(current, previous);&lt;/DIV&gt;</description>
      <pubDate>Fri, 05 Jan 2024 09:53:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2781884#M510982</guid>
      <dc:creator>chaitanyakumarD</dc:creator>
      <dc:date>2024-01-05T09:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to display value of variable having different data types like number,string,images,date &amp;amp</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2783360#M511053</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;some metrics like "Date", "DateTime", and "String" store their values in the String value (string_value) field, you can try grabbing that one.&lt;BR /&gt;&lt;BR /&gt;As for the ones that have a "Metric Definition" table behind them, you can try something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/) {
       
    var assessmentResponses = [];

    var assessmentQuestionGR = new GlideRecord('asmt_assessment_instance_question');
    assessmentQuestionGR.addQuery('instance', current.sys_id);
    assessmentQuestionGR.addQuery('valueISNOTEMPTY');
    assessmentQuestionGR.query();

    while (assessmentQuestionGR.next()) {
        var question = assessmentQuestionGR.metric.getDisplayValue(); // Use getDisplayValue() for reference fields

        var metricDefGr = new GlideRecord('asmt_metric_definition');
        metricDefGr.addQuery('metric', assessmentQuestionGR.metric);
        metricDefGr.addQuery('value', assessmentQuestionGR.value);
        metricDefGr.query();

        var answer = metricDefGr.next() ? metricDefGr.display : "";

        assessmentResponses.push({
            question: question,
            answer: answer
        });

    }
    // Update RITM Additional Comments with assessment responses
    var ritm = new GlideRecord('sc_req_item');
    if (ritm.get('sys_id', current.task_id)) {

        var additionalComments = "\nAssessment Responses:\n";
        for (var i = 0; i &amp;lt; assessmentResponses.length; i++) {
            additionalComments += assessmentResponses[i].question + ': ' + assessmentResponses[i].answer + '\n';
        }

        ritm.comments += additionalComments;
        ritm.update();
    }

})(current, previous);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BUT, you need to get rid of the nested call first (e.g. by using a prefetch), as it's a bad practice for performance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards, Ivan&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jan 2024 14:49:46 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2783360#M511053</guid>
      <dc:creator>Ivan Betev</dc:creator>
      <dc:date>2024-01-07T14:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to display value of variable having different data types like number,string,images,date &amp;amp</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2783616#M511063</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/648013"&gt;@chaitanyakumarD&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Typically, the Display value of the Metric (Question) is stored in the &lt;STRONG&gt;String Value&lt;/STRONG&gt; field as per the Assessment Metric Definitions&lt;/SPAN&gt;. But within the Assessment Instance Questions [asmt_assessment_instance_question] table currently used from your script, the String Value field is not fully populated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try to pull data from the &lt;STRONG&gt;Metric Result [asmt_metric_result]&lt;/STRONG&gt; table instead. This way, you can retrieve the answer along with the display value through the &lt;STRONG&gt;String Value&lt;/STRONG&gt; field.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Timi_0-1704687818018.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/318907i090E8542D26DDAB1/image-size/medium?v=v2&amp;amp;px=400" alt="Timi_0-1704687818018.png" title="Timi_0-1704687818018.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So your script could be like sample below.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/ ) {
 
    var assessmentResponses = [];
    var assessmentQuestionGR = new GlideRecord('asmt_metric_result'); //replace the table
    assessmentQuestionGR.addQuery('instance', current.sys_id);
	assessmentQuestionGR.addNotNullQuery('actual_value'); //replace the field name
    //assessmentQuestionGR.addQuery('valueISNOTEMPTY');
    assessmentQuestionGR.query();
    while (assessmentQuestionGR.next()) {
        var question = assessmentQuestionGR.metric.getDisplayValue();
        var answer = assessmentQuestionGR.string_value.toString(); //replace to string_value
 
        assessmentResponses.push({
            question: question,
            answer:  answer
        });
 
    }
    // Update RITM Additional Comments with assessment responses
    var ritm = new GlideRecord('sc_req_item');
    if (ritm.get('sys_id', current.task_id)) {
 
        var additionalComments = "\nAssessment Responses:\n";
        for (var i = 0; i &amp;lt; assessmentResponses.length; i++) {
            additionalComments += assessmentResponses[i].question + ': ' + assessmentResponses[i].answer + '\n';
        }
 
        ritm.comments += additionalComments;
        ritm.update();
    }
 
 
})(current, previous);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Tai Vu&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2024 04:32:06 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2783616#M511063</guid>
      <dc:creator>Tai Vu</dc:creator>
      <dc:date>2024-01-08T04:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to display value of variable having different data types like number,string,images,date &amp;amp</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2784003#M511090</link>
      <description>&lt;P&gt;hi I have tried that also but it is not populating the results as desired even they are not reference fields also&amp;nbsp;&lt;/P&gt;&lt;P&gt;thankyou for your response&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2024 10:17:36 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2784003#M511090</guid>
      <dc:creator>chaitanyakumarD</dc:creator>
      <dc:date>2024-01-08T10:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to display value of variable having different data types like number,string,images,date &amp;amp</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2784029#M511098</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/648013"&gt;@chaitanyakumarD&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For better understanding of the specific challenges you're encountering, can you provide more information in your business rule? Table, when to run, your advanced script, etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Tai Vu&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2024 10:35:36 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2784029#M511098</guid>
      <dc:creator>Tai Vu</dc:creator>
      <dc:date>2024-01-08T10:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to display value of variable having different data types like number,string,images,date &amp;amp</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2789950#M511511</link>
      <description>&lt;P&gt;thank you timi thats working fine and i have done similar changes only now its working fine .&lt;/P&gt;&lt;P&gt;now i have another qustion&amp;nbsp;&lt;/P&gt;&lt;P&gt;there is screen short captured in the answers , i wnt that to populate it on same RITM additional comments as a link so that whenever we click the link i want show a preview of that snippet to be viewed&amp;nbsp; how can we acheive this ,?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 02:48:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2789950#M511511</guid>
      <dc:creator>chaitanyakumarD</dc:creator>
      <dc:date>2024-01-12T02:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to display value of variable having different data types like number,string,images,date &amp;amp</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2791913#M511664</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/648013"&gt;@chaitanyakumarD&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can leverage the &lt;STRONG&gt;GlideSysAttachment&lt;/STRONG&gt; API to retrieve the associated attachments of the question.&lt;/P&gt;&lt;P&gt;Then you can build a reference link to open the attachment viewer.&lt;/P&gt;&lt;P&gt;Sample below.&lt;/P&gt;&lt;P&gt;Based on the script I provided before, let add an exception in the while loop.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    var assessmentResponses = [];
    var assessmentQuestionGR = new GlideRecord('asmt_metric_result'); //replace the table
    assessmentQuestionGR.addQuery('instance', current.sys_id);
    assessmentQuestionGR.addNotNullQuery('actual_value'); //replace the field name
    //assessmentQuestionGR.addQuery('valueISNOTEMPTY');
    assessmentQuestionGR.query();
    while (assessmentQuestionGR.next()) {
        var question = assessmentQuestionGR.metric.getDisplayValue();

		//If the question is in Attachment datatype
        if (assessmentQuestionGR.metric.datatype.toString() === 'attachment') {
            var attachments = [];
            var attachment = new GlideSysAttachment();
            var agr = attachment.getAttachments('asmt_metric_result', current.getUniqueValue()); //get all attachments
            while (agr.next()) {
				var attachmentID = agr.getUniqueValue();
				var attachmentName = agr.getValue('file_name');
				//build the url to open the document viewer
				var uri = '[code]&amp;lt;a href="sys_attachment.do?view=true&amp;amp;sys_id=' + attachmentID + '"&amp;gt;' + attachmentName + '&amp;lt;/a&amp;gt;[/code]';
                attachments.push(uri);
            }

			assessmentResponses.push({
                question: question,
                answer: attachments.join(',') //set answer
            });
			continue; //skip below lines and move to next question record in the loop
        }

        var answer = assessmentQuestionGR.string_value.toString(); //replace to string_value
        assessmentResponses.push({
            question: question,
            answer: answer
        });

    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Enjoy your result&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Timi_0-1705292747079.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/321064i437CF6C2D56DBEE5/image-size/medium?v=v2&amp;amp;px=400" alt="Timi_0-1705292747079.png" title="Timi_0-1705292747079.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Timi_1-1705292755906.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/321065i6BFF72679E0C57DA/image-size/medium?v=v2&amp;amp;px=400" alt="Timi_1-1705292755906.png" title="Timi_1-1705292755906.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Make sure you have enabled Document Viewer in the table.&lt;/P&gt;&lt;H3&gt;Ref: &lt;A href="https://docs.servicenow.com/bundle/vancouver-servicenow-platform/page/administer/form-administration/task/enable-document-viewer.html" target="_self"&gt;Enable Document Viewer&lt;/A&gt;&lt;/H3&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Tai Vu&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 04:27:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-display-value-of-variable-having-different-data-types/m-p/2791913#M511664</guid>
      <dc:creator>Tai Vu</dc:creator>
      <dc:date>2024-01-15T04:27:12Z</dc:date>
    </item>
  </channel>
</rss>

