PrashantLearnIT
Tera Sage

Hello Everyone,

 

Did you know you could make a string field a hyperlink in list view? In the list view by default only the first field and reference fields appear as hyperlinks but using the [code][/code] tag any string field can be made as a hyperlink in the list view. The link can be used to point to a specific table, with a specific filter and can be populated using Business Rule,etc.

This can be useful in cases wherein we have to link to a list of CIs updated by discovery for example.

Try below steps in your PDI:

  1. Take any string field or create a new one and add attribute No Truncate to true(change to advanced view and add no_truncate=true to the attribute field).
  2. Enter [code]<a href="/cmdb_ci_list.do" target="_blank">10</a>[/code] in the value and save the form.
  3. Go to the list view and add the field if not in the list view. The field should appear as a link to the CI table.

 

If my content helped you in anyway, please mark this content as BOOKMARK, SUBSCRIBE & HELPFUL

 

Best Regards,

Prashant Kumar (LearnIT)

 

YouTube Channel LearnIT: https://www.youtube.com/@learnitwithprashant

Blog LearnIT: https://medium.com/@LearnITbyPrashant

Prashant Kumar LinkedIn: https://www.linkedin.com/in/learnitbyprashant/

ServiceNow Community Prashant Kumar - https://www.servicenow.com/community/user/viewprofilepage/user-id/19635

Comments
Kilo Sage

@PrashantLearnIT 
it didn't work for me, 

Tera Sage

Hi @AnimeshP_96 

 

Can you send screenshot please?

Kilo Sage

sure @PrashantLearnIT 

AnimeshP_96_0-1715672295321.png

 

AnimeshP_96_1-1715672400507.png

 

this is screenshot, let me know if this works..

Kilo Sage

@PrashantLearnIT 
any inputs from your end?

Tera Sage

I will get back to You @AnimeshP_96 

Tera Explorer

@AnimeshP_96  

no_truncate attribute value must be set to true (no_truncate=true)

The [code][/code],  This syntax must be given in calculated value field.

For example return "[code]{syntax}[/code]"

Kilo Sage

ok let me try this and get back @hashwanth 

thanks

Kilo Sage

@hashwanth 
thanks it worked.!!

ServiceNow Employee
ServiceNow Employee

@PrashantLearnIT , 

 

I am planning to send a query as well along with the table name. 

The query is dynamic, like I want to add a reference field's sys_id in the query.

cmdb_ci_list.do?sysparm_query=location%3Df48b202a0a0a0ba7004d9fdfb817015d

 

except that I want to declare a variable for the sys_id and use it.

 

Any idea how that could be implemented within the [code][/code] tags?

Tera Contributor

I have a similar problem. 

I have a string field at my table. When I click on the field on the list view I like to open a new tab and use the URL I save in another field. 

For example: 
I have a field named 'x' and another called 'xURL'. 
When I click on 'x' in the list view I like to pop up a new tab with the URL that I have in 'xURL'.

I succeeded in doing it in form view but didn't in list view. 

Tera Contributor

@AnimeshP_96 can you provide screenshot how and where you have used [code] bite

Tera Contributor

@Or Kalev2 Can you explain and share a screenshot how you have achieved your requirement in form view

Tera Contributor

@krishnagadamset 

No prblem. 

I created Client Script (Type = onLoad).

The Client Script will update the form as needed. 
In the example below you can see that I have 2 fields (field1 & field2) that I updated every load of the form, and there are 2 fields (field1Url & field2Url) that I take the URLs that I needed when the field clicked, the URL fields are hidden via UI Policy.

function onLoad() {
   g_form.getControl('field1').style.color = 'green';
   g_form.getControl('field1').style.fontWeight = 'bold';
   g_form.getControl('field1').style.textDecoration = 'underline';
   g_form.getControl('field1').onmouseover = mouseOver;
   g_form.getControl('field1').onclick = onField1Clicked;
   
   g_form.getControl('field2').style.color = 'red';
   g_form.getControl('field2').style.fontWeight = 'bold';
   g_form.getControl('field2').style.textDecoration = 'underline';
   g_form.getControl('field2').onmouseover = mouseOver;
   g_form.getControl('field2').onclick = onField2Clicked;

   function mouseOver()
   {
      this.style.cursor = 'pointer';
   }

   function onField1Clicked()
   {
		var url = g_form.getValue('field1Url');
		g_navigation.open(url, '_blank');
   }

   function onField2Clicked()
   {
		var url = g_form.getValue('field2Url');
		g_navigation.open(url, '_blank');
   }
       
}

 
If you have any more questions let me know.

Mega Sage
Mega Sage

Hello @PrashantLearnIT ,

This is not working on the portal. It is showing backend value.

How to achieve this on the portal?

 

 

 

 

Tera Sage

Hi @PPPanchal 

 

What is not working and what you have tried?

 

Tera Contributor

Hi,

Value in the field changes to "[code]<a href="/cmdb_ci_list.do" target="_blank">10</a>[/code]" , we need original value there .

dhony_0-1732501863117.png

 

Thanks,

Dhony

 

Tera Contributor

Hi @PrashantLearnIT ,

Its not working as it is changing the field value to calculated value which is "[code]<a href="/cmdb_ci_list.do" target="_blank">10</a>[/code]" .

 

Please provide your suggestions if any.

Tera Sage

Hi @dhony @PPPanchal @krishnagadamset 

 

Guys, read the blog carefully. The link will display in a list view. I have added a screenshot of how this works.

Screenshot 2024-11-26 101155.png

 

Tera Contributor

Hi @PrashantLearnIT ,

link is displaying in list but form value is not correct its changing original field value to backend calculated value.

can you please share the form value of your field how it looks like.

 

Regards,

Dhony

Tera Sage

Hi @dhony 

 

Value is code only, that can be populated using BR according to our needs and requirements, these are already mentioned in blog if you read it completely from start to end

Tera Explorer

Hello @PrashantLearnIT 


[code]<a href="/cmdb_ci_list.do" target="_blank">10</a>[/code]
But in the above code if I replace "/cmdb_ci_list.do" with any link its not working.
I want to direct to a URL page instead of directing to a table.

Is there any solution?

Tera Sage

Hi @varsha-v-shetty 

 

Please generate correct URL

Tera Explorer

Hi @PrashantLearnIT 

The code works when there is no special characters like '?' or '=' in URL but if the URL is associated with any key value (with special characters), it's not working.

Is there any solution?

Tera Explorer

Hi @PrashantLearnIT 

The code works when there is no special characters like '?' or '=' in URL but if the URL is associated with any key value (with special characters), it's not working.

Is there any solution?

Tera Contributor

Hi 

is there any option where we can invoke a function.

i want to have link in Link in List view to invoke the record and show it in GlideModal

Tera Expert

@varsha-v-shetty, I found the same thing you did; this feature doesn't seem to work if there's a query string attached to the URL. I tried URL-encoding all of the special characters in the URL, one by one, but none of this helped to make URL's with query strings work.

 

I was able to get a URL to an application's home portal page to work, so it's not limited to Native UI pages, but as soon as I add the query string to go to the portal page for a specific record, it fails. I'll keep looking into this. Maybe you had some progress in the last 7 months. 😉

Tera Expert

@varsha-v-shetty, I responded too soon; I just figured it out. The problem character in URL query strings is the "&". Initially, I tried using "%26"; this type of encoding works for most of the other special characters, but does not work for "&". After a little more reading, I found another encoding:  &amp;  I replaced all of the "&" characters in my URL query string with "&amp;" and it finally worked. 

 

None of the other special characters I used caused any issues:  ?, =

 

I had also considered using the "encodeURIComponent()" Javascript function, but the other solution worked, so I didn't go any further with this. At some point, I will likely check this out as well.

 

Tera Expert

hi, @PrashantLearnIT   

 

What about in workspace list view, its not work in workspace.

 

Regards.

Tera Expert

I thought we're supposed to avoid "[code][/code]"?

Tera Patron

This is helpful trick to make a string hyperlinked in list view.