Add link in info message

alexm3
Kilo Expert

Hello,

I have the following client script:

--------------------

function onChange(control, oldValue, newValue, isLoading) {

  if (newValue == '')

  return;

  if (newValue == 'ABC')

  g_form.addInfoMessage('Please see knowledge article KB0011111');

  else

  g_form.clearMessages();

----------------------

This script will add an info message at the top of the page when value is ABC. My question is, can I make the KB number as a hyperlink so that people could click on the KB number and be redirected to the its page?

Thanks,

Alex

1 ACCEPTED SOLUTION

Inactive_Us1137
Mega Expert

Hi Alexandru, Michal



It is possible to add the link in the addinfomessage. Please find the sample script below.



function onLoad() {


    g_form.addInfoMessage("Please <a href = '/incident_list.do'>Click</a>");


   


}


Replace the above url with the one your looking to add.



Thanks


Abhishek


PS - Please mark this Helpful, Like, or Correct Answer if relevant.


View solution in original post

10 REPLIES 10

michal29
Mega Guru

Hello Alexandru,



Trough addInfoMessage i belive it is not possible.


I overcome this as appending the link to variable via scripting on the form.


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Alexandru,



You can add a hyperlink in following manner in client side i.e Client Script


Query knowledge table and get the sys_id of the KB article and Knowlede Number



var sysId = //sys_id of the KB Article


var kbNumber = //KB article number


var knowledgeURL = 'https://yourInstanceName.service-now.com/kb_knowledge.do?sys_id='+sysId;



var urlString = '<p><a class="web" target="_blank" href="' + knowledgeUrl + '">' + kbNumber + '</a></p>';


g_form.addInfoMessage("Please see knowledge article "+urlString);



target = "_blank" will open the URL in new tab


target = "_self" will open the URL in same window



This will suffice. I had earlier used the same approach and it worked.



I hope this helps.


Please mark correct & helpful based on impact.



Regards


Ankur Bawiskar


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur,



Thank you for your reply.



How do I combine your script with mine so that I can achieve what I need? I tried what you suggested and I'm getting some errors.



PS: I'm not very experienced with scripting.



Alex


Hi Alexandru,



I just gave you a format for forming the URL.


You just need to replace the 2 variables i.e.


var sysId = //sys_id of the KB Article


var kbNumber = //KB article number


and also change the yourInstanceName to the instance you are using.



Rest all is same.


PS - Please mark it as Correct Answer if relevant.


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader