Trying to add display text to a URL field type

jefff1
Kilo Explorer

Hi Community,

 

I have a script that is populating a HTML link into a field type of URL.   The script and link are working perfectly but since the full URL in the link column takes up a good portion of list view screen, I'm trying to figure out if it is possible to change the syntax to use a displayed text string instead of the full link yet keep the link functional.   Trying to incorporate <a href> tags doesn't work.   I'm wondering if anyone else has done this or has any ideas.

 

Thank you,

 

Jeff Franklin

 

Simplified Code Excerpt:

var myLink=gs.getProperty('glide.servlet.uri') + 'time_card_list.do?sysparm_query=user.name%3D' + myList[c-1][1];

tcs.u_link = myLink;

tcs.insert();

10 REPLIES 10

jefff1
Kilo Explorer

Another approach to solve the problem would be not showing the URL field at all and adding the link to another displayed field much like how a reference field link takes you to the referenced record or how the link in the first displayed column in list view takes you to the record. Does anyone know how to go about adding a custom link to a field?



Jeff


benc
Tera Contributor

I'm not sure if what you are asking for is possible given the layout of the URL field itself. That said, a possible workaround here would be a UI policy that executes a script that changes the value of the link.



When you set the value of a URL field, the actual link itself has an (HTML) ID that is formatted as follows:



table.fieldname_link



So for your example, if u_link is on the incident table, the ID would be:


incident.u_link_link



So you can create a UI policy on that table that changes the innerHTML value of this link (in my example, the field name is u_url_field):



When to Apply


Condition: (name of field) is not empty


Global Checked


Reverse if False Checked


On Load checked



Script


Run Scripts checked


Here's the code for your "execute if true":


function onCondition() {
         document.getElementById("incident.u_link_link").innerHTML = "Click me!";
}

This will change the display text of that link to "Click me!," while retaining the destination of the link:


Screen Shot 2014-11-21 at 4.46.09 PM.png



A few things to note:


  • Since this is client-side, it could take a second to execute, meaning the full link will be visible for a split second
  • This won't execute until the page reloads (in other words, after setting the value of the URL field, the form has to be saved for this to execute)
  • I don't know if this will have any effect on the mobile/tablet site


If you can find a server-side way of doing this, that would probably be preferable, if not, this is probably an OK workaround.



--Ben


Hi Ben,



Am facing the same issue, on incident table only i have url field, but value is not changing in form, i tried above solution, no result. Can you suggest me any other solution for the same problem please.



Regards,


Swathi


jefff1
Kilo Explorer

Hi Ben,



Your suggestion works great on the form.   Unfortunately this is needed for the time card records and they are really only viewed in list view.   Do you know if it is possible to apply the same type of approach to the URL fields in a list view?



Jeff