The CreatorCon Call for Content is officially open! Get started here.

UI Page, redirect when page is loading

whitewalker
Kilo Contributor

I have a UI Page. Before page loads, I need to make a redirect based on condition.

I tried something like this, but didn't work.

<g:evaluate jelly="true">

                      var v = new GlideRecord("myTable");

                      v.addQuery("sys_id",jvar_XXXX)

                      v.query();

                      v.next();

                      if(!v.field)

                      {

                      gs.sendRedirect("/redirect to anothe ui page");

                      }

</g:evaluate>

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Nick,



You could do something like this where you do the lookup in the jelly code and then redirect using javascript:



<g:evaluate jelly="true">


                      var url = '';


                      var v = new GlideRecord("myTable");


                      v.addQuery("sys_id",jvar_XXXX)


                      v.query();


                      if (v.next())


                      {


                      url = v.something;


                      }


</g:evaluate>


<script>


document.observe("dom:loaded", function() {


  window.location = '${url}';


});


</script>


I thought about using js, but i would like a solution without usign js.


That pretty much the standard way to do a redirect with a ui page. Why don't you want to use js?


I suppose you could do it with a meta tag as well:



<g:evaluate jelly="true">


                      var url = '';


                      var v = new GlideRecord("myTable");


                      v.addQuery("sys_id",jvar_XXXX)


                      v.query();


                      if (v.next())


                      {


                      url = v.something;


                      }


</g:evaluate>


<meta http-equiv="refresh" content="2;url=${url}" />