Display a hyperlink on the label for a checkbox

snuser2708
Kilo Contributor

I have requirement to display a hyperlink embedded into the text for checkbox type variable that is defined on a catalog item. I  was able to get the link to show using an onLoad script as follows:

function onLoad() {
$$('label').each(function(i){
     if (i.innerHTML.indexOf('Honorarium') >-1) {
		var text =  "<a href='http://www.google.com'>"+"Link"+"</a>";
           i.innerHTML = "Honorarium " + text;
     }
});   
}

and the link shows as below:

 

find_real_file.png

But when I click on the hyperlink, it does not take to the website. What am I doing wrong?

4 REPLIES 4

Tim Deniston
Mega Sage

When I tried this in my PDI, I found the following error in the console:

 

Mixed Content: The page at 'https://[...].service-now.com/nav_to.do?uri=%2Fcom.glideapp.servicecatalog_cat_item_view.do%3Fv%3D1%26sysparm_id%3D04b7e94b4f7b4200086eeed18110c7fd' was loaded over HTTPS, but requested an insecure resource 'http://www.google.com/'. This request has been blocked; the content must be served over HTTPS.

 

Add target='_blank' in the <a> tag and it will work:

 

function onLoad() { $$('label').each(function(i){ if (i.innerHTML.indexOf('Honorarium') >-1) { var text = "<a href='http://www.google.com' target='_blank'>"+"Link"+"</a>"; i.innerHTML = "Honorarium " + text; } }); }

This works in UI16, but not in Service Portal.  Currently running London, Patch 3

Do you have a solution for Service Portal?

iDNS
Tera Expert

Hi,

Did you ever get this to work? I seem to have similar request & running into issues. Thanks

Allen Andreas
Administrator
Administrator

Hi,

This won't work on the service portal (at least for Kingston and London). To get any form of html/link and all that to show you have to create a widget Service Portal > Service Portal Configuration (in back-end navigation), add your html to the html section of that widget (i.e. <a href="http://www.google.com">Click here for Google</a>), then create a macro variable on the form (catalog item or otherwise) and on the "Default Value" tab of that variable, pick the widget for the widget field:

find_real_file.png

This won't show right next to the checkbox (like as it's own label), but does allow for HTML/LINK to be placed near it if this and the checkbox are next to each other via sequence order.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!