Skip to content

Instantly share code, notes, and snippets.

@thisnameissoclever
Last active March 20, 2018 01:24
Show Gist options
  • Save thisnameissoclever/2c73044d99d35f47534a45fb708b0698 to your computer and use it in GitHub Desktop.
Save thisnameissoclever/2c73044d99d35f47534a45fb708b0698 to your computer and use it in GitHub Desktop.
ServiceNow "Try in Portal" button
https://snprotips.com/blog/2018/3/15/service-catalog-try-in-portal-button
function openPortalPageList() {
var itemID = g_form.getUniqueValue();
var gwPortals = new GlideDialogWindow('try_item_portal_page');
gwPortals.setTitle('Try Portal Page (select portal)');
gwPortals.setPreference('portal_page_id', 'sc_cat_item');
gwPortals.setPreference('item_id', itemID);
gwPortals.render();
}
function goThere(suffix, id, item) {
var url = new GlideURL('/' + suffix);
url.addParam('id', id);
url.addParam('sys_id', item);
var w = getTopWindow();
GlideDialogWindow.get().destroy();
w.popupOpenFocus(url.getURL(), 'try_portal_page', 950, 700, '', false, false);
}
<j:set var="jvar_page_id" value="${RP.getWindowProperties().get('portal_page_id')}"/>
<j:set var="jvar_item_id" value="${RP.getWindowProperties().get('item_id')}"/>
<g:evaluate var="jvar_gr" object="true" jelly="true">
// find existing portals
var grPortal = new GlideRecord("sp_portal");
grPortal.query();
grPortal;
</g:evaluate>
<j:while test="${grPortal.next()}">
<div style="padding:4px;" onclick="goThere('${grPortal.url_suffix}', '${jvar_page_id}', '${jvar_item_id}')">${grPortal.title} (/${grPortal.url_suffix})</div>
</j:while>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment