<?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 Access GlideRecord from within service portal widget. in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/access-gliderecord-from-within-service-portal-widget/m-p/1984481#M641407</link>
    <description>&lt;HR /&gt;
&lt;P class="ng-scope"&gt;How can I run a Glide query from in a widget? (Service Portal)&lt;/P&gt;
&lt;P class="ng-scope"&gt;This code runs fine in the script-background editor, but it doesn't work in the Server-script section of my widget:&lt;/P&gt;
&lt;PRE class="ng-scope  language-markup"&gt;&lt;CODE&gt;var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232");  // hardcoded good sample
destination_sys_id = grTask.sys_id;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I run the code in Scripts, I get:&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;*** Script: sys_id: 0f4d...905&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;When I run it in the widget, I get:&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;{}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To elaborate on my Widget code:&lt;/P&gt;
&lt;DIV id="label.sp_widget.template"&gt;&lt;LABEL class=" col-xs-12 col-md-1_5 col-lg-2 control-label" for="sp_widget.template"&gt;&lt;SPAN class="label-text" title=""&gt;Body HTML template&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;data.test={ {data.test} }&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN class="label-text" title=""&gt;&lt;SPAN class="label-text" title=""&gt;Server script&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;(function(){
  var destination_sys_id = "initialized";
  var grTask = new GlideRecord('task');
  grTask.get('number', "REQ0323232");
  destination_sys_id = grTask.sys_id;
  data.test = destination_sys_id;
})()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Wed, 04 Dec 2019 20:33:34 GMT</pubDate>
    <dc:creator>patrickhunt</dc:creator>
    <dc:date>2019-12-04T20:33:34Z</dc:date>
    <item>
      <title>Access GlideRecord from within service portal widget.</title>
      <link>https://www.servicenow.com/community/developer-forum/access-gliderecord-from-within-service-portal-widget/m-p/1984481#M641407</link>
      <description>&lt;HR /&gt;
&lt;P class="ng-scope"&gt;How can I run a Glide query from in a widget? (Service Portal)&lt;/P&gt;
&lt;P class="ng-scope"&gt;This code runs fine in the script-background editor, but it doesn't work in the Server-script section of my widget:&lt;/P&gt;
&lt;PRE class="ng-scope  language-markup"&gt;&lt;CODE&gt;var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232");  // hardcoded good sample
destination_sys_id = grTask.sys_id;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I run the code in Scripts, I get:&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;*** Script: sys_id: 0f4d...905&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;When I run it in the widget, I get:&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;{}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To elaborate on my Widget code:&lt;/P&gt;
&lt;DIV id="label.sp_widget.template"&gt;&lt;LABEL class=" col-xs-12 col-md-1_5 col-lg-2 control-label" for="sp_widget.template"&gt;&lt;SPAN class="label-text" title=""&gt;Body HTML template&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;data.test={ {data.test} }&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN class="label-text" title=""&gt;&lt;SPAN class="label-text" title=""&gt;Server script&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;(function(){
  var destination_sys_id = "initialized";
  var grTask = new GlideRecord('task');
  grTask.get('number', "REQ0323232");
  destination_sys_id = grTask.sys_id;
  data.test = destination_sys_id;
})()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 04 Dec 2019 20:33:34 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/access-gliderecord-from-within-service-portal-widget/m-p/1984481#M641407</guid>
      <dc:creator>patrickhunt</dc:creator>
      <dc:date>2019-12-04T20:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Access GlideRecord from within service portal widget.</title>
      <link>https://www.servicenow.com/community/developer-forum/access-gliderecord-from-within-service-portal-widget/m-p/1984482#M641408</link>
      <description>&lt;P&gt;You should be able to do access GlideRecord from your service portal widget. When you say it doesn't work, what you do mean? It looks like you're assigned the sys_id of that record to an already declared server side JS variable. What are you doing with that variable that makes you think it doesn't work?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 20:58:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/access-gliderecord-from-within-service-portal-widget/m-p/1984482#M641408</guid>
      <dc:creator>Brad Tilton</dc:creator>
      <dc:date>2019-12-04T20:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Access GlideRecord from within service portal widget.</title>
      <link>https://www.servicenow.com/community/developer-forum/access-gliderecord-from-within-service-portal-widget/m-p/1984483#M641409</link>
      <description>&lt;P&gt;instead of&lt;/P&gt;
&lt;P&gt;destination_sys_id = grTask.sys_id;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try this:&lt;/P&gt;
&lt;P&gt;destination_sys_id = grTask.sys_id.toString();&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:29:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/access-gliderecord-from-within-service-portal-widget/m-p/1984483#M641409</guid>
      <dc:creator>nataliya_b</dc:creator>
      <dc:date>2019-12-04T21:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: Access GlideRecord from within service portal widget.</title>
      <link>https://www.servicenow.com/community/developer-forum/access-gliderecord-from-within-service-portal-widget/m-p/1984484#M641410</link>
      <description>&lt;P&gt;Generally, you want to use getters and setters when working with GlideRecord, so I would do grTask.getValue('sys_id') rather than grTask.sys_id.toString().&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 13:32:36 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/access-gliderecord-from-within-service-portal-widget/m-p/1984484#M641410</guid>
      <dc:creator>Brad Tilton</dc:creator>
      <dc:date>2019-12-05T13:32:36Z</dc:date>
    </item>
  </channel>
</rss>

