UI Action Related Link

DylanB
Tera Guru

Hi all, I created a UI action in our dev instance that opens an external URL. It worked fine in dev so I copied it to Prod manually and now it does not work. The UI action shows on the correct catalog task, but when clicking it, nothing happens. I have also checked my popup settings and allowed them.

 

Is there anything I missed on this?

DylanB_0-1705342835376.png

DylanB_2-1705342873174.png

 

 

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @DylanB 

Let's try below tricks from Now Support KB.

Firstly, it is important that you have the "client" checkbox ticked so that the script can be executed on the client side.

Then in the onclick field, you should specify the function used to trigger the new URL to open

i.e openWindow()

Example 1:

 

 

function openWindow(){
top.window.open('https://www.google.com','_blank') ;
}

 

 

 

Example 2:

 

 

function openWindow(){
var url = 'https://www.google.com';
g_navigation.openPopup(url);
}

 

 

 

Note that the URL has "https://" appended to the URL. Without this protocol, the system will treat your URL as a relative path and append it to your instance URL i.e

https://<your-instance-name>.service-now.com/www.google.com 

 

Ref: KB0721369 - How can I open a non-servicenow website from a UI action?

 

And also try to avoid dot-walking to the sys_id of a reference field in your condition.

It is not necessary to include the sys_id of a reference field when dot-walking, as in the following example:

 

var id = current.caller_id.sys_id; // Wrong

 

The value of a reference field is a sys_id. When you dot-walk to the sys_id, the system does an additional database query to retrieve the caller_id record, then retrieves the sys_id. This can lead to performance issues. Instead, use the statement.

 

var id = current.getValue('caller_id'); // Right

 

 

 

Cheers,

Tai Vu

View solution in original post

4 REPLIES 4

woodyfairley
Tera Guru

Check with your admins and also your desktop security support team to see if external links are blocked. As for me, I created a UI Macro and UI Formatter for external links as this is really simple to do, then drag it onto your form view to the desired location. Hope this helps.

Tai Vu
Kilo Patron
Kilo Patron

Hi @DylanB 

Let's try below tricks from Now Support KB.

Firstly, it is important that you have the "client" checkbox ticked so that the script can be executed on the client side.

Then in the onclick field, you should specify the function used to trigger the new URL to open

i.e openWindow()

Example 1:

 

 

function openWindow(){
top.window.open('https://www.google.com','_blank') ;
}

 

 

 

Example 2:

 

 

function openWindow(){
var url = 'https://www.google.com';
g_navigation.openPopup(url);
}

 

 

 

Note that the URL has "https://" appended to the URL. Without this protocol, the system will treat your URL as a relative path and append it to your instance URL i.e

https://<your-instance-name>.service-now.com/www.google.com 

 

Ref: KB0721369 - How can I open a non-servicenow website from a UI action?

 

And also try to avoid dot-walking to the sys_id of a reference field in your condition.

It is not necessary to include the sys_id of a reference field when dot-walking, as in the following example:

 

var id = current.caller_id.sys_id; // Wrong

 

The value of a reference field is a sys_id. When you dot-walk to the sys_id, the system does an additional database query to retrieve the caller_id record, then retrieves the sys_id. This can lead to performance issues. Instead, use the statement.

 

var id = current.getValue('caller_id'); // Right

 

 

 

Cheers,

Tai Vu

Hi Tai, I tried example 1 and it worked. I removed "top" from top.window.open and it stopped working, so that seemed to be the missing piece. I changed my existing script to the script below and it's working again. I appreciate the help!

DylanB_0-1705413503280.png

 

Thank you!  This worked for opening my url in a new tab.  My URL is just pointing at a KB article.  Can you help me with the workspace script?  I need a button for workspace that will do the same thing, open a URL in a separate tab.

 

My script:

function openWindow(){
top.window.open('MY URL'_blank') ;
}

 

Thanks,

Jonathan