How to add a dynamic URL to the label?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2015 12:43 AM
Hi,
Is it possible to add a dynamic URL to the label. There is a URL field in the label record, but it's static.
Suppose if I want the URL to be like "http://instance.service-now.com/table-name/sys_id=<sys_id fetched from a reference field>"
This means, for each record, the URL will be different and not the same.
Is it possible to do?
Regards,
Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2015 01:34 AM
You can store different URLs in the URL type field for each record. But what do mean URL to the label?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2015 02:01 AM
Hi Guhan,
What I mean is, create a date field, add it to the form, edit the label of the field, and add something in the "URL" field in the label.
The URL you specify will make that label "a link". i.e. when you click on the label, it'll take you to that URL.
My question was, can this URL be made dynamic?
Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2015 03:00 AM
You cannot make it dynamic from the label definition. You may have to do DOM manipulation to achieve this in an onload client script. See the example code below,
if($('status.<record_table_name>.<name_of_field>').next()) {
$('status.<record_table_name>.<name_of_field>').next().href = 'http://instance.service-now.com/table-name/sys_id='+sysID;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2015 05:14 AM
Hi Guhan,
Thanks for your response.
I tried your suggestion. It doesn't work
$('status.<record_table_name>.<name_of_field>').next().href = <url> ----> doesn't set the href attribute of the <label> tag which is next to the one which you fetch. In fact, href is an attribute of <a> tag, right? I wouldn't expect it to work with <label> tag.
I tried to insert <a> tag within the <label> tag, like this. But it doesn't work as well. I'm getting the error "html is not a function".
Code:
var labelElement = $('status.<table_name>.<field_name>').next();
var txt = labelElement.innerText;
labelElement.style.backgroundColor = "#cd6666"; // ----> This works
labelElement.html('<a href="www.google.com">' + txt + '</a>'); // ------> This doesn't work and the error I see is "labelElement.html is not a function"
Any ideas please?
Bala