<?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: Widget set catalog item variable after c.server.update() in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/1408043#M64969</link>
    <description>&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;c.server.update()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;returns a &lt;CODE style="display: inline;"&gt;Promise&lt;/CODE&gt;, so if you write the code&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;c.server.update();
$scope.page.g_form.setValue('ci_data', c.data.display);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the 2nd instruction will be executed as soon as the server call is issued, long before the answer arrives.&lt;/P&gt;
&lt;P&gt;Perhaps try&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;c.server.update().then(onPromiseFulfilled(c, $scope.page.g_form));

function onPromiseFulfilled (c, g_form) {
	return function (data) {
		c.data.display = data.display;
		g_form.setValue('ci_data', c.data.display);
	}
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also "save" a &lt;CODE style="display: inline;"&gt;$watch&lt;/CODE&gt; by setting up an event handler:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;$scope.page.g_form.$private.events.on('onChange', function (fieldName, originalValue, newValue) {
	// Replace with actual code checking the modified field and acting when necessary
	console.log('onChange', fieldName, originalValue, newValue);
});&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 01 Apr 2022 17:45:44 GMT</pubDate>
    <dc:creator>-O-</dc:creator>
    <dc:date>2022-04-01T17:45:44Z</dc:date>
    <item>
      <title>Widget set catalog item variable after c.server.update()</title>
      <link>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/1408042#M64968</link>
      <description>&lt;P&gt;Widget novice here.&lt;/P&gt;
&lt;P&gt;I have a widget that we use to dynamically display some data on a catalog item.&amp;nbsp; It monitors changes to a variable (configuration item) and then makes a server call to see if some specific data exists for that ci.&amp;nbsp; If it does it renders the HTML.&amp;nbsp; After the c.server.update() happens I also want to update a variable on the catalog item that lets me know if data was found.&amp;nbsp; (Using $scope.page.g_form.setValue('ci_data', c.data.display);)&lt;/P&gt;
&lt;P&gt;My issue is that the value of c.data.display is the value before the most recent call to c.server.update();&amp;nbsp;&amp;nbsp; How do I update my catalog item variable to a value set in the most recent run of the server script?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;HTML&lt;BR /&gt;&amp;lt;div ng-if="c.data.display"&amp;gt;CI information goes here.&amp;lt;/div&amp;gt;&lt;BR /&gt;&lt;BR /&gt;Client Controller&lt;BR /&gt;$scope.$watch(function () {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return $scope.page.g_form.getValue('configuration_item');&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}, function (ci) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ci) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;c.data.ci = ci;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;c.server.update();&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $scope.page.g_form.setValue('ci_data', c.data.display);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;});&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 15:51:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/1408042#M64968</guid>
      <dc:creator>Ryan M</dc:creator>
      <dc:date>2022-04-01T15:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Widget set catalog item variable after c.server.update()</title>
      <link>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/1408043#M64969</link>
      <description>&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;c.server.update()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;returns a &lt;CODE style="display: inline;"&gt;Promise&lt;/CODE&gt;, so if you write the code&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;c.server.update();
$scope.page.g_form.setValue('ci_data', c.data.display);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the 2nd instruction will be executed as soon as the server call is issued, long before the answer arrives.&lt;/P&gt;
&lt;P&gt;Perhaps try&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;c.server.update().then(onPromiseFulfilled(c, $scope.page.g_form));

function onPromiseFulfilled (c, g_form) {
	return function (data) {
		c.data.display = data.display;
		g_form.setValue('ci_data', c.data.display);
	}
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also "save" a &lt;CODE style="display: inline;"&gt;$watch&lt;/CODE&gt; by setting up an event handler:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;$scope.page.g_form.$private.events.on('onChange', function (fieldName, originalValue, newValue) {
	// Replace with actual code checking the modified field and acting when necessary
	console.log('onChange', fieldName, originalValue, newValue);
});&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Apr 2022 17:45:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/1408043#M64969</guid>
      <dc:creator>-O-</dc:creator>
      <dc:date>2022-04-01T17:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Widget set catalog item variable after c.server.update()</title>
      <link>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/1408044#M64970</link>
      <description>&lt;P&gt;Most excellent, this worked great.&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 12:58:50 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/1408044#M64970</guid>
      <dc:creator>Ryan M</dc:creator>
      <dc:date>2022-04-04T12:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Widget set catalog item variable after c.server.update()</title>
      <link>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/1408045#M64971</link>
      <description>&lt;P&gt;Glad it works and you're most welcome. I appreciate the feedback too!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 15:08:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/1408045#M64971</guid>
      <dc:creator>-O-</dc:creator>
      <dc:date>2022-04-04T15:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Widget set catalog item variable after c.server.update()</title>
      <link>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/3115816#M1162219</link>
      <description>&lt;P&gt;&lt;A href="https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0715296" target="_blank"&gt;https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0715296&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;g_setValue is not working for me what is the alternative&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/87862"&gt;@Ryan M&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2024 06:17:20 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/3115816#M1162219</guid>
      <dc:creator>Subhendu1</dc:creator>
      <dc:date>2024-11-29T06:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Widget set catalog item variable after c.server.update()</title>
      <link>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/3116548#M1162397</link>
      <description>&lt;P&gt;Should we guess what &lt;FONT face="courier new,courier" color="#FF0000"&gt;g_setValue&lt;/FONT&gt; is?&lt;/P&gt;</description>
      <pubDate>Sat, 30 Nov 2024 12:28:20 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/3116548#M1162397</guid>
      <dc:creator>-O-</dc:creator>
      <dc:date>2024-11-30T12:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Widget set catalog item variable after c.server.update()</title>
      <link>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/3116571#M1162402</link>
      <description>&lt;P&gt;I was able to figure out why g_form.SetValue wasn't working we have to define g_form in the beginning&amp;nbsp; to inspect form objects .&lt;/P&gt;</description>
      <pubDate>Sat, 30 Nov 2024 14:15:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/3116571#M1162402</guid>
      <dc:creator>Subhendu1</dc:creator>
      <dc:date>2024-11-30T14:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Widget set catalog item variable after c.server.update()</title>
      <link>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/3116572#M1162403</link>
      <description>&lt;P&gt;&lt;A href="https://www.servicenow.com/community/developer-forum/unable-to-access-g-form-in-widget-code/m-p/1847753" target="_blank"&gt;https://www.servicenow.com/community/developer-forum/unable-to-access-g-form-in-widget-code/m-p/1847753&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Nov 2024 14:18:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/widget-set-catalog-item-variable-after-c-server-update/m-p/3116572#M1162403</guid>
      <dc:creator>Subhendu1</dc:creator>
      <dc:date>2024-11-30T14:18:07Z</dc:date>
    </item>
  </channel>
</rss>

