Unable to convert full link into a small text hyperlink

Shankha B
Tera Contributor

Hi all. I have a requirement to create one hyperlink from script and attach the link in all the records of xyz table. I have created one field which is URL type. I am also able to create the link from the script and successfully set the value in the URL field. Now It is taking all the full URL. I want to show a title like "click here" in the list view so that when user clicks on it, he /she will be redirected to the page. Please refer to this code below:

 

var hostName = gs.getProperty('glide.servlet.uri'); // Get the instance base URL

var portal = "portal_identifier"; // Replace with your portal identifier

var page = "page_identifier"; // Replace with your page identifier

var sysId = current.sys_id.toString(); // Get the record sys_id var link = hostName + "sp?id=" + page + "&table=" + current.getTableName() + "&sys_id=" + sysId + "&spa=1";

var htmlLink = '<a href="' + link + '">Click Here</a>'; // Create an HTML hyperlink

current.your_field = htmlLink;

current.update();

 

Even if I do this it is taking the anchor tag in the link also. I have tried with HTML field type but the link is not accessible from the list view.

 

Also is there any attribute in the dictionary of URL field type that I can use to shorten the link so that it looks clean. 

 

Need some help! Thanks in advance.

4 REPLIES 4

Alka_Chaudhary
Mega Sage
Mega Sage

Hello @Shankha B  ,

 

Please refer to @Chuck Tomasi 's solution via the provided link.

 

Thanks,

Alka Chaudhary.

swathisarang98
Giga Sage
Giga Sage

Hi @Shankha B  ,

 

I found something related to this you can refer the below article ,

https://john-james-andersen.com/blog/service-now/making-linky-lists-in-servicenow-list-views.html 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

Hi Swathi, 

Thanks for the link. I have followed the instructions but after passing the link in the href it is populating as string value.

I am pasting my code that I have used after seeing the instruction. This is after creating the url.

var link = hostName + "sp?id=" + page + "&table=" + current.getTableName() + "&sys_id=" + sysId ;

  current.u_url_string = "[code]<a href='";
  current.u_url_string += link;
  current.u_url_string += "' target='_blank'>View Story</a>[/code]";
 
But when I am navigating to my table I am not able to see any hyper link. It is taking as string value with the anchor tag present in the same.

Shankha B
Tera Contributor

t