Field Messages - showFieldMsg()

revlass
Tera Contributor

I need help embedding a link into a field message.
I have tried the following...

var str = "here";
if (g_form.getValue('service_type') == 'System Request') {
g_form.showFieldMsg('service_type', 'You are submitting a system request; please provide the following additional information regarding your request: \nCost/Benefit Analysis (Please complete the spreadsheet found ' + str.link('www.something_here.com') + ' and attach to this request using the paperclip icon)', 'info', false);
}

The result was...

You are submitting a system request; please provide the following additional information regarding your request: Cost/Benefit Analysis (Please complete the spreadsheet found a href="www.something_here.com">here a and attach to this request using the paperclip icon)

Any help on this would be great. Thanks!

17 REPLIES 17

You're correct on Prototype. It's loaded on every page.


Hi Mark,

 

Wanted to draw your attention to this post:

 

https://community.servicenow.com/community?id=community_question&sys_id=bdda50c2db54af485129a851ca961970

 

Kindly provide your valuable inputs.

 

Thanks!

DaleHurtt
Kilo Contributor

The "problem" with the solution provided at Generate link in client script gs.showFieldMsg is that writing to innerHTML the way it was overwrites the info message icon (the green check mark). A better way is to do the following:


function onLoad() {
// Show an info message with an embedded hypertext link.
var str = "",
placeholder = "##placeholder##";
g_form.showFieldMsg('u_field1', placeholder, 'info', false);
str = $$('div.outputmsg_info')[0].innerHTML;
str = str.substring (0, str.indexOf (placeholder));
$$('div.outputmsg_info')[0].innerHTML = str + "Go <a href='http://www.something_here.com' target ='_blank'>here</a>";
}


By using a searchable placeholder you can extract out the

element's HTML and append new HTML to it. The result is what you are looking for, shown in the attached image.

I also happened to blog about working my way through this problem (I am crazy like that), as it may someday help me remember this! :^) http://dales-tech-notes.blogspot.com/2012/04/adventures-with-javascript-and.html

Dale Hurtt
http://dales-tech-notes.blogspot.com


Thanks Dale! This has been the closest I've been to getting this done.

I am trying to tailor this to it will work with an onChange script instead of onLoad.

The idea behind it is that if a user tries to enter an incident that is critical, a message would pop up prompting them to call the help desk and a link to the form that has the contact information is in the message.

I can copy paste this in to an onLoad script and it works like a charm. However, if I run it in an onChange, it throws an error when I I go to the incident form.

TypeError: Cannot read property 'innerHTML' of undefined function

Here is the whole blob..

onChange script error: TypeError: Cannot read property 'innerHTML' of undefined function onChange_incident_priority_4(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == '') { return; } if(newValue<3) { var str = "", placeholder = "##placeholder##"; g_form.showFieldMsg('priority', placeholder, 'error', false); str = $$('div.outputmsg_info')[0].innerHTML; str = str.substring (0, str.indexOf (placeholder)); $$('div.outputmsg_info')[0].innerHTML = str + "If you are reporting a critical ticket, please contact your local Help Desk directly."; } }

##placeholder##

Any ideas what I am missing here?

Thanks!


Hi Dale,

This does not seem to work in Kingston version. Also, your blogs are no longer available. Please help. 

Thanks

 

 

Hi Giuseppe, 

Can you please guide me on how it worked? 

Thanks