Display hyperlink instead of full url in URL field

carlh
Kilo Guru

Good morning,

Yesterday I got some help from ctomasi and it's working great!     Can we concatinate 2 fields to complete a URL?

Recap.

I have a URL field that is created by concatenating 2 values.   For extra credit, I would like to show a hyper link rather than the full ugly URL on the form.   Can this be done?

Please advise and thank you!!!

Regards,

Carl

21 REPLIES 21

Hi Carl,



Here's my idea (it needs some HTML styling).



Create a UI Macro (System UI> Macro). Mine is called "website". The name matters because it is used as a formatter which you can add to the form.



My simple UI macro looks like this:



find_real_file.png



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <g:evaluate jelly="true">


  var gr = new GlideRecord(jelly.jvar_ref_table);


  if (gr.get(jelly.sys_id)) {


  gs.log('url=' + gr.u_url);


  }



  </g:evaluate>


  Website: <a target="_blank" href='${gr.u_url}'>LINK</a>


</j:jelly>



Next, create a formatter (System UI> Formatter)



find_real_file.png



Make sure the Formatter field is the name of your macro defined above.



Finally, place the field on the form using the usual methods (Configure> Form Layout or Configure> Form Design). You will find your formatter listed with the other formatters (like Activities (filtered)).


find_real_file.png



Granted, mine's not the prettiest thing, with a little HTML style and table for alignment, it can be better. The top URL is the original field value. The bottom "Website" has a clickable link that opens in a new window.



find_real_file.png



http://wiki.servicenow.com/index.php?title=UI_Macros


Creating a Formatter - ServiceNow Wiki  


Wow! Thanks Chuck!   I'm going to give it a shot.  



I'm also going to try out the solution abhi_r   provided.



This looks like it's going to take a while so I'll reply back when I get a chance!


Abhi did a great job with the client script. However, I need to point out that his solution uses DOM manipulation which puts it at risk of not working in future releases if the developers decide to change the DOM (again). Mine is all supportable.


I agree with chuck . You are good until your element id does not change


which is very rare.



On Wednesday, September 14, 2016, carlh <community-no-reply@servicenow.com>


Hi, Chuck,


Your info is great help, just wondering how can we add the current table.field1 to the link rather than just a general url link (www.amazon.com)?  


For example, The url field1 is like https://mysite.service-now.com/nav_to.do?uri=incident.do?sys_id=0acc20d24f3a8a00a9ef0f1f0310c7ff&my_... , which field2 is another field in the incident table.



Thanks a lot.


-James