hyper link in showFieldMsg on load client script

Alon Grod
Tera Expert

How can I add hyper link using onLoad client script and

 g_form.showFieldMsg

(for example the user will see 'click here' and it will redirect to google)

My field name is: u_priferia

table name: sn_slm_case

Tanushree Maiti
Tera Patron

Hi @Alon Grod 

 

By default, ServiceNow's  g_form.showFieldMsg treats text as plain string and escapes HTML tags.

OOB it is not supported. 

You need to write an onLoad Client Script that pushes a placeholder message and dynamically updates the DOM element  ( DOM is not recommended).

 

Refer  for DOM onload script: 

https://www.servicenow.com/community/itsm-forum/need-help-in-adding-a-link-in-string-type-field/td-p...

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Aditya_hublikar
Mega Sage

Hello @Alon Grod ,

 

Here it look like :

Aditya_hublikar_0-1781599164459.png

 

You can try this code snippet :

function onLoad() {
    var fieldName = 'u_incident'; 
    var placeholder = "##placeholder##";
    var url = "https://google.com"; /
    
   
    g_form.showFieldMsg(fieldName, placeholder, 'info', false);
    
 
    try {
        var elements = document.getElementsByClassName("fieldmsg notification notification-info");
        if(elements.length > 0) {
            var str = elements[0].innerHTML;
            str = str.substring(0, str.indexOf(placeholder));
            elements[0].innerHTML = str + 'Please <a href="' + url + '" target="_blank">click here</a> for more information.';
        }
    } catch(e) {
        // Fallback or error handling
    }
}

 

Note : uncheck isolated script 

 

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya

 

Ankur Bawiskar
Tera Patron

@Alon Grod 

g_form.showFieldMsg doesn't support HTML so your requirement is not possible

You can inform your customer about this platform limitation and instead show infoMessage on form

Note: There are approaches to achieve this with DOM manipulation but it's not recommended to use

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

vaishali231
Kilo Sage

Hey @Alon Grod 

You can achieve this using DOM manipulation from an onLoad Client Script.

function onLoad() {
    g_form.showFieldMsg('u_priferia', 'Click here', 'info');
    setTimeout(function() {
        var msgs = document.querySelectorAll('.fieldmsg');
        msgs.forEach(function(msg) {
            if (msg.innerText.indexOf('Click here') > -1) {
                msg.innerHTML = '<a href="https://www.google.com" target="_blank">Click here</a>';
            }

        });

    }, 1000);
}

Important: Make sure Isolate Script is unchecked on the Client Script, otherwise DOM APIs such as document.querySelectorAll() will not be accessible.

vaishali231_0-1781607588208.png

 

 

Note: Direct DOM manipulation is generally not recommended in ServiceNow because DOM elements and CSS classes can change across releases, which may cause scripts to break after upgrades. Where possible, consider supported alternatives such as UI Macros, Formatters, HTML fields, or Workspace components depending on your use case.

***********************************************************************************************************************************

If this response helps, please mark it as Accept as Solution and Helpful.

Doing so helps others in the community and encourages me to keep contributing.

Regards

Vaishali Singh

Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb