<?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 Help with 'Summary of Requested Item' Script in RITM workflow in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430981#M87907</link>
    <description>&lt;P&gt;Background:&lt;/P&gt;
&lt;P&gt;We are using the script below to add a summary of the requested item in our catalog items to the work notes of the the sc_task. This was previously only used in catalog items with 1:1 relationships for Request -&amp;gt; Requested Item -&amp;gt; Service Catalog Task.&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.request.sys_id);
gr.query();

while (gr.next()) {
    // Get Owned Variables for Requested Item and sort by Order
    var ownvar = new GlideRecord('sc_item_option_mtom');
    ownvar.addQuery('request_item.number', gr.number);
    ownvar.addQuery('sc_item_option.value', '!=', '');
    ownvar.orderBy('sc_item_option.order');
    ownvar.query();

    var items = "Summary of " + gr.number + ":   " + gr.cat_item.getDisplayValue() + "\n\n";

    while (ownvar.next()) {

        var field = ownvar.sc_item_option.item_option_new;
        var fieldValue = ownvar.sc_item_option.item_option_new.name;
        // Print variable name
        items += field.getDisplayValue() + ": " + gr.variables[fieldValue].getDisplayValue() + "\n";

    }
}
task.work_notes = items;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Issue:&lt;/P&gt;
&lt;P&gt;We've recently begun utilizing an onboarding order guide in our service catalog and I've identified an issue that I need some help with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When someone uses the order guide, which will create 1-3 separate requested items depending on their needs, the resulting work note is being duplicated across all sc_task records rather than displaying the summary of the unique RITM associated with it.&lt;/P&gt;
&lt;P&gt;I've tried adding timers to the workflow prior to sc_task creation as well as renaming the 'items' variable to unique names for each workflow, but receive the same result.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Has anyone run into this or know of a potential solution? The requested item summary is helpful to our technicians when they need to seek additional approval.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Kevin&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jan 2022 18:49:52 GMT</pubDate>
    <dc:creator>Kevin Ng</dc:creator>
    <dc:date>2022-01-24T18:49:52Z</dc:date>
    <item>
      <title>Help with 'Summary of Requested Item' Script in RITM workflow</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430981#M87907</link>
      <description>&lt;P&gt;Background:&lt;/P&gt;
&lt;P&gt;We are using the script below to add a summary of the requested item in our catalog items to the work notes of the the sc_task. This was previously only used in catalog items with 1:1 relationships for Request -&amp;gt; Requested Item -&amp;gt; Service Catalog Task.&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.request.sys_id);
gr.query();

while (gr.next()) {
    // Get Owned Variables for Requested Item and sort by Order
    var ownvar = new GlideRecord('sc_item_option_mtom');
    ownvar.addQuery('request_item.number', gr.number);
    ownvar.addQuery('sc_item_option.value', '!=', '');
    ownvar.orderBy('sc_item_option.order');
    ownvar.query();

    var items = "Summary of " + gr.number + ":   " + gr.cat_item.getDisplayValue() + "\n\n";

    while (ownvar.next()) {

        var field = ownvar.sc_item_option.item_option_new;
        var fieldValue = ownvar.sc_item_option.item_option_new.name;
        // Print variable name
        items += field.getDisplayValue() + ": " + gr.variables[fieldValue].getDisplayValue() + "\n";

    }
}
task.work_notes = items;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Issue:&lt;/P&gt;
&lt;P&gt;We've recently begun utilizing an onboarding order guide in our service catalog and I've identified an issue that I need some help with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When someone uses the order guide, which will create 1-3 separate requested items depending on their needs, the resulting work note is being duplicated across all sc_task records rather than displaying the summary of the unique RITM associated with it.&lt;/P&gt;
&lt;P&gt;I've tried adding timers to the workflow prior to sc_task creation as well as renaming the 'items' variable to unique names for each workflow, but receive the same result.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Has anyone run into this or know of a potential solution? The requested item summary is helpful to our technicians when they need to seek additional approval.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Kevin&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 18:49:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430981#M87907</guid>
      <dc:creator>Kevin Ng</dc:creator>
      <dc:date>2022-01-24T18:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help with 'Summary of Requested Item' Script in RITM workflow</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430982#M87908</link>
      <description>&lt;P&gt;Is this code written in workflow? Can you do this in a business role written on sc_task table. It could be a after insert business role and your first line should change to -&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.request_item.toString());  - changed here
gr.query();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also the last line should change to -&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;current.work_notes = items&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The intention is that business rule will only trigger per unique tasks and thus would remove duplicates.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 03:13:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430982#M87908</guid>
      <dc:creator>Sumit Pandey1</dc:creator>
      <dc:date>2022-01-25T03:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Help with 'Summary of Requested Item' Script in RITM workflow</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430983#M87909</link>
      <description>&lt;P&gt;Hi Sumit,&lt;/P&gt;
&lt;P&gt;This code is written in the workflow. I created an after insert BR on the sc_task table as you recommended but I'm not seeing the summary in the work notes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you take a look at the BR code? I may have misread your instructions...&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.request_item.toString());
gr.query();

while (gr.next()) {
    // Get Owned Variables for Requested Item and sort by Order
    var ownvar = new GlideRecord('sc_item_option_mtom');
    ownvar.addQuery('request_item.number', gr.number);
    ownvar.addQuery('sc_item_option.value', '!=', '');
    ownvar.orderBy('sc_item_option.order');
    ownvar.query();

    var items = "Summary of " + gr.number + ":   " + gr.cat_item.getDisplayValue() + "\n\n";

    while (ownvar.next()) {

        var field = ownvar.sc_item_option.item_option_new;
        var fieldValue = ownvar.sc_item_option.item_option_new.name;
        // Print variable name
        items += field.getDisplayValue() + ": " + gr.variables[fieldValue].getDisplayValue() + "\n";

    }
}
current.work_notes = items;

})(current, previous);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Kevin&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 15:39:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430983#M87909</guid>
      <dc:creator>Kevin Ng</dc:creator>
      <dc:date>2022-01-25T15:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Help with 'Summary of Requested Item' Script in RITM workflow</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430984#M87910</link>
      <description>&lt;P&gt;Just wanted to follow up to my previous post in case anyone else finds this helpful. Below is the final script that's working as intended now.&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.request_item.toString());
gr.query();

while (gr.next()) {
    // Get Owned Variables for Requested Item and sort by Order
    var ownvar = new GlideRecord('sc_item_option_mtom');
    ownvar.addQuery('request_item.number', gr.number);
    ownvar.addQuery('sc_item_option.value', '!=', '');
    ownvar.orderBy('sc_item_option.order');
    ownvar.query();

    var items = "Summary of " + gr.number + ":   " + gr.cat_item.getDisplayValue() + "\n\n";

    while (ownvar.next()) {

        var field = ownvar.sc_item_option.item_option_new;
        var fieldValue = ownvar.sc_item_option.item_option_new.name;
        // Print variable name
        items += field.getDisplayValue() + " " + gr.variables[fieldValue].getDisplayValue() + "\n";

    }
}
	
current.work_notes = items;
	
current.update();

})(current, previous);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks for your help Sumit!&lt;/P&gt;
&lt;P&gt;Kevin&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 19:21:40 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430984#M87910</guid>
      <dc:creator>Kevin Ng</dc:creator>
      <dc:date>2022-02-18T19:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Help with 'Summary of Requested Item' Script in RITM workflow</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430985#M87911</link>
      <description>&lt;P&gt;So nice of you to update the thread, thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Feb 2022 02:29:04 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-summary-of-requested-item-script-in-ritm-workflow/m-p/1430985#M87911</guid>
      <dc:creator>Sumit Pandey1</dc:creator>
      <dc:date>2022-02-21T02:29:04Z</dc:date>
    </item>
  </channel>
</rss>

