How to add a dynamic URL to the label?

balakumar1
Kilo Contributor

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

9 REPLIES 9

Bala,



There should be a <span> element with id as 'status.<table_name>.<field_name>' just above the <a href> which doesn't have an id. So the code I gave is to access the href by first accessing the span above it and next() will give the control of subsequent element which is <a href>. I tried it and it works for me. Try an alert before setting.



alert($('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;


Guhan,



Unfortunately, in our instance (Eureka patch9), the element next to <span> is not <a>, rather it is <label>... like this



<span id="status.table_name.field_name" class=" label_description" title="" mandatory="false" oclass="">  </span><label for="table_name.field_name" onclick="return labelClicked(this);" dir="ltr">ACTUAL LABEL DISPLAYED ON FORM</label>



Bala


srinivasboppana
Kilo Expert

if($('status.incident.opened_at').next()) {


  $('status.incident.opened_at').next().innerHTML = '<a href="https://dev16082.service-now.com/incident.do?sys_id="+g_form.getUniqueValue()+">Opened</a>';


  }



try it like this


Srinivas,



Thanks. This works. But the link that appears on the form is not clickable. I tried in chrome, firefox, and IE. It doesn't work in any of them.


Any idea why?



Bala


I know this is kind of old, and you've probably moved on, but I got this working. You still need to define the URL in the Label Configuration. In your case then, this should be " href="https://dev16082.service-now.com/incident.do?sys_id="


I discovered this by first creating a client script with the suggested code, and it worked, so I figured I didn't need the text in the URL field for the label, so I removed it. It stopped working. The label appeared to be a URL, but clicking it didn't do anything. I put the incomplete URL back in the URL field, and it started working again.