Unable to convert full link into a small text hyperlink
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2024 11:05 PM - edited ‎02-15-2024 04:50 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2024 11:35 PM
Hello @Shankha B ,
Please refer to @Chuck Tomasi 's solution via the provided link.
Thanks,
Alka Chaudhary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2024 11:39 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2024 12:45 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2024 12:30 AM - edited ‎02-15-2024 12:46 AM
t