How to convert sys id in an URL to system property or by other means

Brett Lindsey1
Tera Contributor

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');

}

 

5 REPLIES 5

Anshu_Anand_
Kilo Sage
function openURL() {

 

    var dash = gs.getProperty('change.calendar');

    var caltab = gs.getProperty('change.calendar.tab');

    g_navigation.openPopup('https://itsmnow.service-now.com/$pa_dashboard.do?sysparm_dashboard='+dash+'&sysparm_tab='+caltab+'&sysparm_cancelable=true&sysparm_editable=false&sysparm_active_panel=false');

}

Can you try this in your UI action.

Also use alert/gs.log() to check if the property value is fetching or not for dash and catlab on click of UI action.

 

If it works please mark the answer as correct

Regards,
Anshu

Thanks for the reply. The code you mention also didnt work. However using the alert/gs.log() to check if the property value is fetching or not resulting in it not fetching. Solution ended up creating a Display BR then capturing the Sys properties in scartchpad then calling the scratchpad in the UI action script. This solved the issue. Thanks for the help

function openURL()
{
/*****************************

getting the dashboard and tab sys_id from getproperties through business rule

Business rule used in - [USB] - Use Scratchpad to Call in UI on Display

**********************/
var dash = g_scratchpad.dash;
var caltab = g_scratchpad.caltab;
var url = "https://itsmnow.service-now.com/$pa_dashboard.do?sysparm_dashboard=" + dash + "&sysparm_tab=" + caltab + "&sysparm_cancelable=true&sysparm_editable=false&sysparm_active_panel=false";
window.open(url);

@anshu 

FYI you cannot use gs object in client side; so the script you shared won't work

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks for pointing it out but for me it works. as a demo, incident form open in new tab when click on ui action button on the incident form. can you please guide me since g_navigation.openPopup and top.window.open both works , what is best practice to use.

find_real_file.png

 

Regards,
Anshu