Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Checking if URL contains certain text

codedude
Mega Expert

I am trying to determine if a URL contains incident.do, if it does contain that I want to send them to the URL in which they clicked on (which would be an incident), otherwise I would like to send them to our ESS portal.

This is only for users with NO roles.

This is what I have and is currently not working:

<g:evaluate>        

            var user = gs.getUser();            

            var gr = new GlideRecord('sys_user_has_role');          

            gr.addQuery('user', user.getID());          

            gr.query();    

</g:evaluate>

<j:if test="${gr.hasNext()}">            

          <script>                    

                      top.location.href = "${sysparm_uri}";        

          </script>

</j:if>

<script>

            var sysparmuri = "${sysparm_uri}";

                      <j:when test="${sysparmuri.indexOf('incident.do') > -1}">

                                  top.location.href = "${sysparm_uri}";

                      </j:when>

                      <j:otherwise>

                                  sysparmuri = decodeURIComponent(sysparmuri.replace("nav_to.do?uri=/", "ess/"));

                                  top.location = sysparmuri;

                      </j:otherwise>        

</script>  

Can anyone see what could be going wrong?

4 REPLIES 4

Mike Allen
Mega Sage

I used this: var table = '${RP.getParameterValue('jvar_ref_table')}'; to get the table (in your case, incident) and then:



if(table == 'incident'){


  name = current.name;


  ciType = 'Server';


  operator = 'contains';


}



That works for me.


Would this replace this portion?



var sysparmuri = "${sysparm_uri}";


<j:when test="${sysparmuri.indexOf('incident.do') > -1}">


          top.location.href = "${sysparm_uri}";


</j:when>


Yeah:



<g:evaluate>


var table = '${RP.getParameterValue('jvar_ref_table')}';


</g:evaluate>


<j:choose>


<j:when test="${table == 'incident'}>


top.location.href = "${sysparm_uri}";


</j:when>


<j:otherwise>


sysparmuri = decodeURIComponent(sysparmuri.replace("nav_to.do?uri=/", "ess/"));


                                  top.location = sysparmuri;


</j:otherwise>


</j:choose>


Hmm, that does not work...



This is what I have now:




<g:evaluate>      


            var user = gs.getUser();          


            var gr = new GlideRecord('sys_user_has_role');        


            gr.addQuery('user', user.getID());        


            gr.query();  


</g:evaluate>  



<j:if test="${gr.hasNext()}">          


            <script>                  


                        top.location.href = "${sysparm_uri}";  


            </script>          


</j:if>



<g:evaluate>


            var table = '${RP.getParameterValue('jvar_ref_table')}';


</g:evaluate>



<j:if test="${!gr.hasNext()}">        


            <j:choose>


                        <j:when test="${table == 'incident'}">


                                    top.location.href = "${sysparm_uri}";


                        </j:when>


                        <j:otherwise>


                                    sysparmuri = decodeURIComponent(sysparmuri.replace("nav_to.do?uri=/", "ess/"));


                                    top.location = sysparmuri;


                        </j:otherwise>


            </j:choose>    


</j:if>





I don't understand what is going wrong here? It looks like it should work....