How to convert sys id in an URL to system property or by other means
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 05:47 PM
I am trying to open URL a new tab when someone clicks an UI action. I got it to work with code below but when I do a healthscan I get an error not to use hard coded sys IDs. Ive turned the sys IDs within the URL to system properties and call them in the URL but am not having any luck. Any idea what wrong or any other suggestions on how to accomplish the goal.
Code that works but get healthscan error:
function openURL() {
window.open('https://itsmnow.service-now.com/$pa_dashboard.do?sysparm_dashboard=9a8184ed1b80b490f6f31f49b04bcba1&sysparm_tab=20e348e91bc0b490f6f31f49b04bcbb2&sysparm_cancelable=true&sysparm_editable=false&sysparm_active_panel=false');
}
Other things ive tried that dont work:
1.
function openURL() {
var dash = gs.getProperty('change.calendar');
var caltab = gs.getProperty('change.calendar.tab');
window.open('https://itsmnow.service-now.com/$pa_dashboard.do?sysparm_dashboard=dash&sysparm_tab=caltab&sysparm_cancelable=true&sysparm_editable=false&sysparm_active_panel=false');
}
2.
function openURL() {
var dash = gs.getProperty('change.calendar');
var caltab = gs.getProperty('change.calendar.tab');
window.open('https://itsmnow.service-now.com/$pa_dashboard.do?sysparm_dashboard=' + dash + '&sysparm_tab=' + caltab + '&sysparm_cancelable=true&sysparm_editable=false&sysparm_active_panel=false');
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2022 08:00 AM
gs.getProperty() won't work in client side and is not allowed
What you can do is use GlideAjax to get the property and then redirect
Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function(){
var arr = [];
var dash = gs.getProperty('change.calendar');
var caltab = gs.getProperty('change.calendar.tab');
arr.push(dash+'');
arr.push(caltab+'');
return arr.toString();
},
type: 'checkRecords'
});
UI Action:
function openURL() {
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "getDetails");
ga.getXMLAnswer(function(answer){
if(answer != ''){
var arr = answer.toString().split(',');
var dash = arr[0];
var caltab = arr[1];
window.open('https://itsmnow.service-now.com/$pa_dashboard.do?sysparm_dashboard=' + dash + '&sysparm_tab=' + caltab + '&sysparm_cancelable=true&sysparm_editable=false&sysparm_active_panel=false');
}
});
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader