<?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: Server script runs twice with AngularJS directive on service portal widget in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/server-script-runs-twice-with-angularjs-directive-on-service/m-p/1415055#M71981</link>
    <description>&lt;P&gt;Maybe but here's what's interesting: I just commented out the entire client script and the server script is still running when the page loads for some reason. Maybe this isn't angular related?&lt;/P&gt;</description>
    <pubDate>Mon, 05 Aug 2019 15:29:52 GMT</pubDate>
    <dc:creator>Zach22</dc:creator>
    <dc:date>2019-08-05T15:29:52Z</dc:date>
    <item>
      <title>Server script runs twice with AngularJS directive on service portal widget</title>
      <link>https://www.servicenow.com/community/developer-forum/server-script-runs-twice-with-angularjs-directive-on-service/m-p/1415053#M71979</link>
      <description>&lt;P&gt;I am working on a service portal widget. I want the initial visibility of the widget/button to depend on the result of a server-side call. I've created a function, c.onLoad() that accomplishes this. If I add&amp;nbsp;&lt;STRONG&gt;onLoad="c.onLoad()"&amp;nbsp;&lt;/STRONG&gt;to the element, the client and server script run only once as they should.&lt;/P&gt;
&lt;P&gt;But if I instead use&amp;nbsp;&lt;STRONG&gt;ng-init="c.onLoad()"&lt;/STRONG&gt;&amp;nbsp;or some other AngualrJS directive that calls the onLoad function, the client script appears to run once but the server script runs twice! I was able to verify this with the client and server logs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see why using the angular directive causes the server script to run twice?&amp;nbsp;Maybe somehow the controller is running twice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/165578i2C68780728CE3966/image-size/large?v=v2&amp;amp;px=999" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;HTML&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;&amp;lt;div style="padding-bottom:5px;"&amp;gt;
&amp;lt;button id="cancel" type="button" class="btn btn-danger btn-block" ng-init="c.onLoad()" &amp;gt;Cancel&amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Client&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function (spModal) {
    /* widget controller */
    var c = this;

    c.onLoad = function () {
        console.log("I only run once");
        c.server.get({
            ...
        }).then(function (r) {
            ...
        });
    }
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Server&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function () {
    gs.log("CHCEK: I should not run twice");
})();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Aug 2019 14:41:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/server-script-runs-twice-with-angularjs-directive-on-service/m-p/1415053#M71979</guid>
      <dc:creator>Zach22</dc:creator>
      <dc:date>2019-08-05T14:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Server script runs twice with AngularJS directive on service portal widget</title>
      <link>https://www.servicenow.com/community/developer-forum/server-script-runs-twice-with-angularjs-directive-on-service/m-p/1415054#M71980</link>
      <description>&lt;P&gt;Just e&amp;nbsp;thought: Is it because you execute the service side function&amp;nbsp;IIFE and then with the c.server.get you trigger server side again?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 15:25:53 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/server-script-runs-twice-with-angularjs-directive-on-service/m-p/1415054#M71980</guid>
      <dc:creator>Thom8</dc:creator>
      <dc:date>2019-08-05T15:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: Server script runs twice with AngularJS directive on service portal widget</title>
      <link>https://www.servicenow.com/community/developer-forum/server-script-runs-twice-with-angularjs-directive-on-service/m-p/1415055#M71981</link>
      <description>&lt;P&gt;Maybe but here's what's interesting: I just commented out the entire client script and the server script is still running when the page loads for some reason. Maybe this isn't angular related?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 15:29:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/server-script-runs-twice-with-angularjs-directive-on-service/m-p/1415055#M71981</guid>
      <dc:creator>Zach22</dc:creator>
      <dc:date>2019-08-05T15:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Server script runs twice with AngularJS directive on service portal widget</title>
      <link>https://www.servicenow.com/community/developer-forum/server-script-runs-twice-with-angularjs-directive-on-service/m-p/1415056#M71982</link>
      <description>&lt;P&gt;Oh yeah, I guess that may be the case. But is there any way to prevent the script from running on load? SN seems to encourage this format as the default?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 15:35:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/server-script-runs-twice-with-angularjs-directive-on-service/m-p/1415056#M71982</guid>
      <dc:creator>Zach22</dc:creator>
      <dc:date>2019-08-05T15:35:47Z</dc:date>
    </item>
  </channel>
</rss>

