<?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: Querying sys_history_line tables in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025637#M682563</link>
    <description>&lt;P&gt;This function is amazing, thanks for&amp;nbsp;sharing the info!&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jul 2018 23:32:48 GMT</pubDate>
    <dc:creator>davidsizu</dc:creator>
    <dc:date>2018-07-10T23:32:48Z</dc:date>
    <item>
      <title>Querying sys_history_line tables</title>
      <link>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025630#M682556</link>
      <description>&lt;P&gt;I have a requirement to query against the sys_history_line table and retrieve some information.&lt;/P&gt;&lt;P&gt;I had a request to display the "fulfilment" date on a Portal record.&lt;/P&gt;&lt;P&gt;On checking a couple of records, I can query the sys_history_set and then the sys_history_line&lt;/P&gt;&lt;P&gt;I soon realised this was not great for the portal so I have added a new field to the sc_request and sc_req_item tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, now I am being asked to back populate the data&lt;/P&gt;&lt;P&gt;i have had a look at pulling from sys_audit and from the sys_history_line tables.&lt;/P&gt;&lt;P&gt;the later are better for my needs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am however finding that when I run a Background Script to get some data I am offten getting a lot of null information for the field I am after.&lt;/P&gt;&lt;PRE __default_attr="java" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14474260753756213 jive_text_macro" data-renderedposition="218_8_1192_160" jivemacro_uid="_14474260753756213"&gt;&lt;P&gt;Script: REQ0015788 : b76ef6ec6f1782402a3e9accbb3ee4ac : 2015-10-21 10:03:36&lt;/P&gt;&lt;P&gt;*** Script: REQ0015776 : 43b86b0d6f6346007115ca727d3ee404 : 2015-11-04 12:40:15&lt;/P&gt;&lt;P&gt;*** Script: REQ0015763 : 6d2d55df6f5f4200b872129e5d3ee424 : 2015-10-29 16:01:48&lt;/P&gt;&lt;P&gt;*** Script: REQ0015756 : 22db3cd76f5f4200b872129e5d3ee43b : 2015-11-05 10:49:29&lt;/P&gt;&lt;P&gt;*** Script: REQ0015750 : d05479956f970200b872129e5d3ee47a : 2015-11-05 10:49:30&lt;/P&gt;&lt;P&gt;*** Script: REQ0015749 : 421179d16f970200b872129e5d3ee4c9 : 2015-11-05 10:49:32&lt;/P&gt;&lt;P&gt;*** Script: REQ0015744 : c2d7c15d6f570200b872129e5d3ee439 : 2015-10-29 16:24:22&lt;/P&gt;&lt;P&gt;*** Script: REQ0015737 : cc16a0496f930200b872129e5d3ee435 : null&lt;/P&gt;&lt;P&gt;*** Script: REQ0015605 : f35b82dc6f5f42402a3e9accbb3ee4eb : null&lt;/P&gt;&lt;P&gt;*** Script: REQ0015600 : 74f84a5c6f5f42402a3e9accbb3ee492 : null&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I now go into the record REQ0015744 and come straight back out and run the Backgroun Script again, I now see the information&lt;/P&gt;&lt;PRE __default_attr="java" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14474261260913226 jive_text_macro" data-renderedposition="420_8_1192_144" jivemacro_uid="_14474261260913226"&gt;&lt;P&gt;*** Script: REQ0015788 : b76ef6ec6f1782402a3e9accbb3ee4ac : 2015-10-21 10:03:36&lt;/P&gt;&lt;P&gt;*** Script: REQ0015776 : 43b86b0d6f6346007115ca727d3ee404 : 2015-11-04 12:40:15&lt;/P&gt;&lt;P&gt;*** Script: REQ0015763 : 6d2d55df6f5f4200b872129e5d3ee424 : 2015-10-29 16:01:48&lt;/P&gt;&lt;P&gt;*** Script: REQ0015756 : 22db3cd76f5f4200b872129e5d3ee43b : 2015-11-05 10:49:29&lt;/P&gt;&lt;P&gt;*** Script: REQ0015750 : d05479956f970200b872129e5d3ee47a : 2015-11-05 10:49:30&lt;/P&gt;&lt;P&gt;*** Script: REQ0015749 : 421179d16f970200b872129e5d3ee4c9 : 2015-11-05 10:49:32&lt;/P&gt;&lt;P&gt;*** Script: REQ0015744 : c2d7c15d6f570200b872129e5d3ee439 : 2015-10-29 16:24:22&lt;/P&gt;&lt;P&gt;*** Script: REQ0015737 : cc16a0496f930200b872129e5d3ee435 : null&lt;/P&gt;&lt;P&gt;*** Script: REQ0015605 : f35b82dc6f5f42402a3e9accbb3ee4eb : null&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arrgh Is there any way I can make this work - it will be a background task run once for the sc_request and sc_req_item tables&lt;/P&gt;&lt;P&gt;It is as if I need to open and inspect each record or somehow force the history tables to work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did try a query against the sys_audit table and it was seemingly having a similar issue&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any ideas would be gratefully received&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2015 15:58:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025630#M682556</guid>
      <dc:creator>poyntzj</dc:creator>
      <dc:date>2015-11-13T15:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Querying sys_history_line tables</title>
      <link>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025631#M682557</link>
      <description>&lt;P&gt;Hi Julian, &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Based on the data you shared it appears that you're not getting null for &lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;REQ0015744&lt;/SPAN&gt; on none of the background scripts. In fact, they appear to have the same time.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Would you mind rephrasing your question so that we can have a better understanding of the problem you're facing?&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Berny&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 15 Nov 2015 03:49:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025631#M682557</guid>
      <dc:creator>bernyalvarado</dc:creator>
      <dc:date>2015-11-15T03:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Querying sys_history_line tables</title>
      <link>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025632#M682558</link>
      <description>&lt;P&gt;Hi Berny&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;If I run a query that will take the sys_id of the REQ record, look at the &lt;STRONG&gt;sys_history_set&lt;/STRONG&gt;. &amp;nbsp; I get the relevant information i need and then try to query the &lt;STRONG&gt;sys_history_line&lt;/STRONG&gt; table to return the latest &lt;STRONG&gt;close_code&lt;/STRONG&gt; entry&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;I need to populate a field on the REQ table&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;When I run the query I often find lots of null entries&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;If I go into the record, at the bottom we see the Activity states - including the one I am searching for&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;If I now got back and run my query again, I now get to see the data from the sys_history_line.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;It is as if I need to force the line to load to do this.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;I did try against the &lt;STRONG&gt;sys_audit&lt;/STRONG&gt; table and got a similar problem&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 15 Nov 2015 19:33:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025632#M682558</guid>
      <dc:creator>poyntzj</dc:creator>
      <dc:date>2015-11-15T19:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Querying sys_history_line tables</title>
      <link>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025633#M682559</link>
      <description>&lt;P&gt;Hi Julian, I now understand what you're looking for. Indeed it's odd how records get added to the audit / history tables. The good news is that there is a work around. &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;On your case you can create an &lt;STRONG&gt;Insert / Update &lt;/STRONG&gt;&lt;STRONG&gt;OnAfter&lt;/STRONG&gt; business rule in the &lt;STRONG&gt;change_request &lt;/STRONG&gt;table and have a script like the following:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __jive_macro_name="quote" class="jive_macro_quote jive_text_macro" data-renderedposition="123_8_1041_41"&gt;&lt;P&gt;new GlideHistorySet("change_request", current.sys_id).generate();&lt;/P&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;That will make the trick &lt;SPAN __jive_emoticon_name="happy" __jive_macro_name="emoticon" class="jive_emote jive_macro" data-renderedposition="195_157_16_16" src="https://www.servicenow.com/8.0.1.35b65d4/images/emoticons/happy.png"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Berny&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Nov 2015 02:25:17 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025633#M682559</guid>
      <dc:creator>bernyalvarado</dc:creator>
      <dc:date>2015-11-16T02:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Querying sys_history_line tables</title>
      <link>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025634#M682560</link>
      <description>&lt;P&gt;I shall have a look at this a little later this week&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Nov 2015 09:10:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025634#M682560</guid>
      <dc:creator>poyntzj</dc:creator>
      <dc:date>2015-11-16T09:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Querying sys_history_line tables</title>
      <link>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025635#M682561</link>
      <description>&lt;P&gt;Sounds good Julian! &lt;SPAN __jive_emoticon_name="happy" __jive_macro_name="emoticon" class="jive_emote jive_macro" data-renderedposition="8_141_16_16" src="https://www.servicenow.com/8.0.1.35b65d4/images/emoticons/happy.png"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;The business rule is really straight forward (since it's just one line of code). Please let me know if you run into any issues or if you have any further questions.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Berny&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Nov 2015 06:16:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025635#M682561</guid>
      <dc:creator>bernyalvarado</dc:creator>
      <dc:date>2015-11-17T06:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Querying sys_history_line tables</title>
      <link>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025636#M682562</link>
      <description>&lt;P&gt;Tried and it on a set of test records it has worked as intended.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Nov 2015 09:18:05 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025636#M682562</guid>
      <dc:creator>poyntzj</dc:creator>
      <dc:date>2015-11-18T09:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Querying sys_history_line tables</title>
      <link>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025637#M682563</link>
      <description>&lt;P&gt;This function is amazing, thanks for&amp;nbsp;sharing the info!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 23:32:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/querying-sys-history-line-tables/m-p/2025637#M682563</guid>
      <dc:creator>davidsizu</dc:creator>
      <dc:date>2018-07-10T23:32:48Z</dc:date>
    </item>
  </channel>
</rss>

