<?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: UI Action redirects to previous page in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2980001#M1127484</link>
    <description>&lt;P&gt;Looks like you also need a&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;action.setRedirectURL(current)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in the first &lt;STRONG&gt;if&lt;/STRONG&gt; statement block so the message shows and you stay on the form and let the message display.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if(openGateCount &amp;gt; 0)
{
	gs.addInfoMessage('ERROR row count is: ' + openGateCount);
	action.setRedirectURL(current);	
}
else&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If that doesn't fix it, set a breakpoint at the first line and step it through using the script debugger, to work out if it is erroring in anyway.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;One other tip&lt;/STRONG&gt; is to use GlideAggregate rather than getRowCount() it's more efficient.&amp;nbsp;&lt;SPAN&gt;g and let the message displayetRowCount() is inferior due to the fact that it iterates the entire record set in order to count the elements&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jul 2024 13:55:45 GMT</pubDate>
    <dc:creator>Paul Curwen</dc:creator>
    <dc:date>2024-07-03T13:55:45Z</dc:date>
    <item>
      <title>UI Action redirects to previous page</title>
      <link>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2979939#M1127468</link>
      <description>&lt;P&gt;Not sure what is causing this, I've modified the script of a server-side UI Action but whenever the UI Action is used it weirdly re-directs to the previous page despite there being no call to redirect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Removing the GlideRecord call and query and reverting back to the original 4 lines (ori) will fix it, but I don't see why a simple GlideRecord check would cause such an issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Might just be something I'm not seeing.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var prjGlid = new GlideRecord('pm_project_task');
prjGlid.addQuery('parent', current.sys_id);
prjGlid.addEncodedQuery('short_description=Initiation Phase Completion^key_milestone=true^active=true');
prjGlid.query();

// get row count for returned records from query
var openGateCount = prjGlid.getRowCount();

if(openGateCount &amp;gt; 0)
{
	gs.addInfoMessage('ERROR row count is: ' + openGateCount);	
}
else
{
	current.phase = 'planning'; // ori
	current.state = '2'; // ori
	current.update(); // ori
	action.setRedirectURL(current); // ori
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 13:21:43 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2979939#M1127468</guid>
      <dc:creator>MBarrott</dc:creator>
      <dc:date>2024-07-03T13:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: UI Action redirects to previous page</title>
      <link>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2980001#M1127484</link>
      <description>&lt;P&gt;Looks like you also need a&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;action.setRedirectURL(current)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in the first &lt;STRONG&gt;if&lt;/STRONG&gt; statement block so the message shows and you stay on the form and let the message display.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if(openGateCount &amp;gt; 0)
{
	gs.addInfoMessage('ERROR row count is: ' + openGateCount);
	action.setRedirectURL(current);	
}
else&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If that doesn't fix it, set a breakpoint at the first line and step it through using the script debugger, to work out if it is erroring in anyway.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;One other tip&lt;/STRONG&gt; is to use GlideAggregate rather than getRowCount() it's more efficient.&amp;nbsp;&lt;SPAN&gt;g and let the message displayetRowCount() is inferior due to the fact that it iterates the entire record set in order to count the elements&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 13:55:45 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2980001#M1127484</guid>
      <dc:creator>Paul Curwen</dc:creator>
      <dc:date>2024-07-03T13:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: UI Action redirects to previous page</title>
      <link>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2980029#M1127495</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/79549"&gt;@Paul Curwen&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That missing action was the trick, greatly appreciate spotting that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you demonstrate how you'd utilize &lt;SPAN&gt;GlideAggregate&amp;nbsp;in this example? Looks like I'd use it in a similar way to GlideRecord.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 14:08:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2980029#M1127495</guid>
      <dc:creator>MBarrott</dc:creator>
      <dc:date>2024-07-03T14:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: UI Action redirects to previous page</title>
      <link>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2980044#M1127501</link>
      <description>&lt;P&gt;Hi, Glad it worked for you &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;, &lt;STRONG&gt;please mark the answer as Correct that would be appreciated&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding using GlideAggregate, these are decent write-ups on it here:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developer.servicenow.com/blog.do?p=/post/glideaggregate/" target="_blank"&gt;https://developer.servicenow.com/blog.do?p=/post/glideaggregate/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.servicenow.com/community/developer-blog/improving-script-performance-with-glideaggregate/ba-p/2793256" target="_blank"&gt;https://www.servicenow.com/community/developer-blog/improving-script-performance-with-glideaggregate/ba-p/2793256&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.karteekn.com/gliderecord-glideaggregate-and-when-to-chose-one-over-the-other/" target="_blank"&gt;https://www.karteekn.com/gliderecord-glideaggregate-and-when-to-chose-one-over-the-other/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically for your scenario you want to use the COUNT option of GlideAggregateit will just make your code run much more efficiently rather than using getRowCount();&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 14:18:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2980044#M1127501</guid>
      <dc:creator>Paul Curwen</dc:creator>
      <dc:date>2024-07-03T14:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: UI Action redirects to previous page</title>
      <link>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2980130#M1127517</link>
      <description>&lt;P&gt;Got GlideAggregate working! Will definitely use this for aggregate queries moving forward. Appreciate the help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 15:08:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/2980130#M1127517</guid>
      <dc:creator>MBarrott</dc:creator>
      <dc:date>2024-07-03T15:08:18Z</dc:date>
    </item>
  </channel>
</rss>

