GlideTransaction API reference

mmongeau
Giga Guru

Can anyone tell me where I can find an API reference for the GlideTransaction object?   I have found multiple examples in the community forums and in Business Rules and Script Includes but it is not listed in the Product Documentation Server API reference (Server API Reference - ServiceNow Wiki)   or in the Developer site API reference (https://developer.servicenow.com/app.do#!/api_doc).

Thanks,

    Michael Mongeau

    Stratus Technologies

16 REPLIES 16

We restrict non-IT users to the CMS portal using some logic in the UI page footer and a Script Include. It checks for roles and then looks at the current transaction to determine how to redirect the user to the CMS portal.



For example, if a request for a knowledge article comes in as /kb_view.do?sysparm_article=KB0010045 and the user has no roles the script will do a GlideRecord query to get the sys_id of the article and redirect the user to /ess/knowledge_do?sysparm_document_key=kb_knowledge,sys_id.



It works great for links sent in email.   It fails when a user is in the portal just browsing the knowledge base (which is the newer V3 in Fuji).   Since the main knowledge splash page is embedded in a iFrame when you click on an article the redirect happens within the iFrame and you end up with two sets of headers/footers.



So basically I trying to figure out how to detect if the user is in the portal regardless of any iFrames.   It's easy on the client side (window.self vs window.top) but challenging on the server side.



  Michael


Michael,



Drop the code below at the bottom of "kb_view" UI Page just before closing Jelly tag.


Based on how the kb_view.do URLs are structured in your environment you may need to modify the URL structure on line 3.


Note: $[current_site] is an object so feel free to dot-walk!


i.e.: $[current_site.default_theme], etc...



Hat tip Nathan Firth



Let me know how it goes!



<j2:if test="$[typeof current_site === 'undefined']">


      <j2:if test="$[!gs.hasRole('itil') || !gs.hasRole('admin')]">


              <!-- here's where your meta http redirect goes to some kind of URL like this >>> https://YOURINSTANCE.service-now.com/ess/knowledge.do?sysparm_document_key=kb_knowledge,${RP.getParameterValue('sys_kb_id')} -->


      </j2:if>


</j2:if>


<j2:if test="$[typeof current_site != 'undefined']">


      <!--Do nothing since this is a KB article running inside a CMS site-->


      <!--Or do something else-->


</j2:if>


The Jive editor was rejecting my XML code because it contained the meta http-equiv refresh tag I think.


Screenshot and attached as TXT


Screenshot:


Screen Shot 2015-08-27 at 12.17.34 AM.png


I found an alternative solution by checking the referring URL of the request.   In the Script Include I get the referer (with the infamous misspelling):



var referer = GlideTransaction.get().getRequest().getHeader("referer");



If the referer contains myinstance.service-now.com then no redirect is done since the user clicked a link on a page in the portal.   Otherwise (referer is null or an external site) the redirect is done.   It's working well so far.



I do like your solution though and I plan to keep it as a fallback in case I run into any problems (like using undocumented features that may go away in the future).



Thanks,



Michael


var referer = GlideTransaction.get().getRequest().getHeader("referer");



This returns null on IE but works well in Chrome. Any idea why? Any replacements? We are on Eureka currently.