Adding a link in error box message

Raghu Loganatha
Kilo Guru

Hi ,
Currently i have a error box message in my client script .

g_form.showErrorBox('*******', "****************************http://***********.");

The above line shows how i have it currently , I would like to have it as

g_form.showErrorBox('*******', "****************************LINK.");
I would like to add a url link to that message, How can i do that???
Your help is much appreciated.

Thanks.

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

Try this



addInfoMessage(message)Displays an informational message for the current session with a blue information icon and a light-blue background.


Can also include HTML in the message! Note that I've replaced the greater than and less than symbols with brackets in the HTML usage example to get it to display correctly here. You'll need to change the brackets back to standard HTML to get it to work in your instance.
gs.addInfoMessage('Session Info Message Text');


//Info message with HTML formatting
//Create the html contents of the information message
var link = '[a href="incident.do?sys_id=' + current.sys_id + '" class="breadcrumb" ]' + current.number + '[/a]';
var message = 'Incident ' + link + ' has been created. ';
message += 'Thank you for your submission.';


//Add the information message
gs.addInfoMessage(message);

Read more here


UI Info and Error Message Cheat Sheet - ServiceNow Guru


-Anurag

Hi Anurag, 

I tried the solution you provided but it did not work for me. So I did the following and it worked like a charm.

find_real_file.png

var link = '<a href="incident.do?sys_id=' + current.sys_id + '" class="breadcrumb" >' + current.number + '</a> ';
	link+='<img src="call.png" width="25" height="41" style="display:inline;"/>';
var message = 'Incident ' + link + ' has been created. ';
message += 'Thank you for your submission.';
gs.addInfoMessage(message);

Chris14
Tera Contributor

I had the same issue and I found a way to use the function. I know this is already an old post, but it is still working (tested in Orlando) and maybe help other ones:

        if (!answer.result) {
            var linkText = "link text";
            var msg = "Example msg ";
            var htmlMsg;
            if (answer.link) {
                htmlMsg = msg + '<a href="' + answer.link + '" target="_blank">' + linkText + '</a>.';
            }
            msg += linkText + ".";
            g_form.showErrorBox('fieldname', msg);
            if (htmlMsg) {
                try {
                    var control = g_form.getControl('fieldname');
                    //console.log(control.parentNode.lastElementChild.firstChild);
                    control.parentNode.lastElementChild.firstChild.innerHTML = htmlMsg;
                } catch (error) {
                    // Ignore
                }
            }
        }

This solution might not work, if you have multiple error messages below the field (will replace maybe text of the wrong error message). But as a quick solution it will do the job:

find_real_file.png

Not tested, if this will also work in the service portal.

Chris14
Tera Contributor

This solution still works with the new UI in San Diego. I just tested it. 😉