Checking if URL contains certain text
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 12:16 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 12:37 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 12:58 PM
Would this replace this portion?
var sysparmuri = "${sysparm_uri}";
<j:when test="${sysparmuri.indexOf('incident.do') > -1}">
top.location.href = "${sysparm_uri}";
</j:when>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 05:44 PM
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 10:12 AM
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....