<?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 How to populate custom field on Request table with value from Requested Item table? in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212019#M865565</link>
    <description>&lt;P&gt;I would like to populate a custom string field (could be changed to a reference field if that is more appropriate?) called "u_catalog_item" I have created on the Request (sc_request) table with the value of the Item (cat_item) field on the Requested Items (sc_req_items) table. I need to filter REQs based on the Catalog Item from which they were created. For example, I have a catalog item "Request to Pull Email". The only place the name of this catalog item appears is on the RITM table. So, I have to populate the field on the REQ table with the "name" value on the RITM table.&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #303a46; font-family: SourceSansPro,Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; word-wrap: break-word;"&gt; This requires matching the records based on REQ### and then populating the custom field.&lt;/SPAN&gt; I have created a business rule to automatically populate the custom field, but am getting stuck on the GlideRecord query to grab the Request numbers and match them to copy the name data. I currently have an after Insert or Update BR that has a script that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; var cat_item = current.u_catalog_item;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; var gs = new GlideRecord('sc_req_item');&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; gs.addQuery('request');&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; gs.query();&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; while (request == sc_request.request){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cat_item = sc_req_item.name;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;Can somebody please tell me what is wrong with this script? Much appreciated&lt;/P&gt;</description>
    <pubDate>Tue, 21 Aug 2018 06:30:55 GMT</pubDate>
    <dc:creator>jaredholm</dc:creator>
    <dc:date>2018-08-21T06:30:55Z</dc:date>
    <item>
      <title>How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212019#M865565</link>
      <description>&lt;P&gt;I would like to populate a custom string field (could be changed to a reference field if that is more appropriate?) called "u_catalog_item" I have created on the Request (sc_request) table with the value of the Item (cat_item) field on the Requested Items (sc_req_items) table. I need to filter REQs based on the Catalog Item from which they were created. For example, I have a catalog item "Request to Pull Email". The only place the name of this catalog item appears is on the RITM table. So, I have to populate the field on the REQ table with the "name" value on the RITM table.&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #303a46; font-family: SourceSansPro,Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; word-wrap: break-word;"&gt; This requires matching the records based on REQ### and then populating the custom field.&lt;/SPAN&gt; I have created a business rule to automatically populate the custom field, but am getting stuck on the GlideRecord query to grab the Request numbers and match them to copy the name data. I currently have an after Insert or Update BR that has a script that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; var cat_item = current.u_catalog_item;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; var gs = new GlideRecord('sc_req_item');&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; gs.addQuery('request');&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; gs.query();&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; while (request == sc_request.request){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cat_item = sc_req_item.name;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;Can somebody please tell me what is wrong with this script? Much appreciated&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 06:30:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212019#M865565</guid>
      <dc:creator>jaredholm</dc:creator>
      <dc:date>2018-08-21T06:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212020#M865566</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Firstly you gave used &lt;STRONG&gt;gs&amp;nbsp;&lt;/STRONG&gt;which is the Global object provided by servicenow for GlideSystem.&lt;/P&gt;
&lt;P&gt;Don't use that and use gr or any other name you wish to.&lt;/P&gt;
&lt;P&gt;And if you want to retirve all the requests the remove the addQuery and just use query.&lt;/P&gt;
&lt;P&gt;then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var gr = new GlideRecord('sc_req_item');&lt;/P&gt;
&lt;P&gt;gr.query();&lt;/P&gt;
&lt;P&gt;while(gr.next())&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;if(//here check you conditions)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;sc_req_item.name = cat_item;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mark correct if it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Omkar Mone&lt;/P&gt;
&lt;P&gt;www.dxsherpa.com&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 06:35:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212020#M865566</guid>
      <dc:creator>Omkar Mone</dc:creator>
      <dc:date>2018-08-21T06:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212021#M865567</link>
      <description>&lt;P&gt;Hi Omkar,&lt;/P&gt;
&lt;P&gt;I currently have this and it still is not working:&lt;/P&gt;
&lt;P&gt;var cat_item = current.u_catalog_item;&lt;BR /&gt;var num = current.number;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var gr = new GlideRecord('sc_req_item');&lt;BR /&gt;gr.query();&lt;BR /&gt;while (gr.next){&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; if (sc_req_item.request == num){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cat_item = sc_req_item.name;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;Is there anything else I should be doing?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 06:48:43 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212021#M865567</guid>
      <dc:creator>jaredholm</dc:creator>
      <dc:date>2018-08-21T06:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212022#M865568</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (&lt;STRONG&gt;sc_req_item.request&lt;/STRONG&gt; == num){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cat_item = &lt;STRONG&gt;sc_req_item.name&lt;/STRONG&gt;;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;This is wrong. You want the request feild value from sc_req_table??&lt;/P&gt;
&lt;P&gt;the use &lt;STRONG&gt;gr.request&lt;/STRONG&gt; and &lt;STRONG&gt;gr.name&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 06:57:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212022#M865568</guid>
      <dc:creator>Omkar Mone</dc:creator>
      <dc:date>2018-08-21T06:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212023#M865569</link>
      <description>&lt;DIV&gt;&amp;nbsp;var cat_item = current.u_catalog_item;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;var num = current.number;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;var gr = new GlideRecord('sc_req_item');&lt;BR /&gt;&amp;nbsp;gr.query();&lt;BR /&gt;&amp;nbsp;while (gr.next){&lt;BR /&gt;&amp;nbsp;&amp;nbsp;if (gr.request == num){&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;cat_item = gr.cat_item.name;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;}&lt;/DIV&gt;
&lt;P&gt;This query ran for over 4 minutes and then did not even update the field.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 07:14:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212023#M865569</guid>
      <dc:creator>jaredholm</dc:creator>
      <dc:date>2018-08-21T07:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212024#M865570</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;gr.cat_item.name&amp;nbsp;&lt;/STRONG&gt;-&amp;gt; wrong.&lt;/P&gt;
&lt;P&gt;gr.name -&amp;gt;right&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 07:17:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212024#M865570</guid>
      <dc:creator>Omkar Mone</dc:creator>
      <dc:date>2018-08-21T07:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212025#M865571</link>
      <description>&lt;P&gt;Please send me the screenshots of the Br or whatever you have written because you are writing it wrong.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 07:19:45 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212025#M865571</guid>
      <dc:creator>Omkar Mone</dc:creator>
      <dc:date>2018-08-21T07:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212026#M865572</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/s/skins/images/290D9EACEF04B5CDA289A122E3F698AA/responsive_peak/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/s/skins/images/290D9EACEF04B5CDA289A122E3F698AA/responsive_peak/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 07:39:06 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212026#M865572</guid>
      <dc:creator>jaredholm</dc:creator>
      <dc:date>2018-08-21T07:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212027#M865573</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/s/skins/images/290D9EACEF04B5CDA289A122E3F698AA/responsive_peak/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/s/skins/images/290D9EACEF04B5CDA289A122E3F698AA/responsive_peak/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 07:40:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212027#M865573</guid>
      <dc:creator>jaredholm</dc:creator>
      <dc:date>2018-08-21T07:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212028#M865574</link>
      <description>&lt;P&gt;The issue is&amp;nbsp;your if statement.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;gr.request&lt;/STRONG&gt; will get the &lt;STRONG&gt;sys_id&lt;/STRONG&gt; of the request.&lt;BR /&gt;&lt;STRONG&gt;num&lt;/STRONG&gt; is the number of the current record.&lt;/P&gt;
&lt;P&gt;You'll never have a match between a number of a record and a sys_id.&lt;/P&gt;
&lt;P&gt;Change &lt;STRONG&gt;var num = current.number&lt;/STRONG&gt; to &lt;STRONG&gt;var reqID = current.getUniqueValue()&lt;BR /&gt;&lt;/STRONG&gt;By doing this you get the sys_id of the current record and can compare it to another sys_id&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 07:46:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212028#M865574</guid>
      <dc:creator>palmen</dc:creator>
      <dc:date>2018-08-21T07:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212029#M865575</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so do when you are saying name what exactly do you want to populate? Because there is no name feild available . Or do you want the display value to RITM ?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 07:47:15 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212029#M865575</guid>
      <dc:creator>Omkar Mone</dc:creator>
      <dc:date>2018-08-21T07:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212030#M865576</link>
      <description>&lt;P&gt;I want the display value of the Item field on the RITM table because this is the name of the catalog item that I need to populate my custom field.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 08:00:24 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212030#M865576</guid>
      <dc:creator>jaredholm</dc:creator>
      <dc:date>2018-08-21T08:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212031#M865577</link>
      <description>&lt;P&gt;To get the display value use this&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;gr.getDisplayValue('cat_item');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 08:05:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212031#M865577</guid>
      <dc:creator>palmen</dc:creator>
      <dc:date>2018-08-21T08:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212032#M865578</link>
      <description>&lt;P&gt;Script should be something like this&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var reqID = current.getUniqueValue()
 
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', reqID);
gr.query();
if (gr.next()){
   current.setValue('u_catalog_item', gr.getDisplayValue('cat_item'));
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 08:11:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212032#M865578</guid>
      <dc:creator>palmen</dc:creator>
      <dc:date>2018-08-21T08:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212033#M865579</link>
      <description>&lt;P&gt;I changed the code to what you have above, the update topped off at 300 seconds and did not complete. Not sure where to go from here.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 08:20:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212033#M865579</guid>
      <dc:creator>jaredholm</dc:creator>
      <dc:date>2018-08-21T08:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate custom field on Request table with value from Requested Item table?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212034#M865580</link>
      <description>&lt;P&gt;That's strange,&amp;nbsp;shouldn't take that amount of time.&lt;/P&gt;
&lt;P&gt;Try adding some logs to the script to see what values you actually get&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var reqID = current.getUniqueValue()
gs.log('Request SYS ID: ' + reqID);
 
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', reqID);
gr.query();
gs.log('BEFORE IF');
if (gr.next()){
   gs.log('ITEM NAME: ' + gr.getDisplayValue('cat_item'))
   current.setValue('u_catalog_item', gr.getDisplayValue('cat_item'));
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you have something else that triggers on the request that could cause this?&lt;/P&gt;
&lt;P&gt;Another issue you have is if you have more than 1 request item related to a request, but that might not be the case for you?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 08:44:46 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-populate-custom-field-on-request-table-with-value-from/m-p/2212034#M865580</guid>
      <dc:creator>palmen</dc:creator>
      <dc:date>2018-08-21T08:44:46Z</dc:date>
    </item>
  </channel>
</rss>

