g_form.showFieldMsg Client scripts is not working on portal

manibaig
Mega Guru

UI Type= All. Below script works fine in servicenow(Kingston) but it's not working on portal. Field message does display on portal for a split second though . Any suggestions guys Thanks 

function onLoad() {
var WTest = g_form.getValue('u_w_status');
if ( WTest== 'Awaiting') {
// alert('What');
g_form.showFieldMsg('WTest','Disclaimer .........' , 'info' , true);
}
}

1 ACCEPTED SOLUTION

Stacy1
Mega Guru

the info,true works great for me.  Are you remembering to hide the message also if it's false.

 

Here is an example of my script and it works great on the portal.

 

function onChange(control, oldValue, newValue, isLoading) {
// if (isLoading || newValue == 'prod') {
if (g_form.getValue('var_environment') == 'prod'){
g_form.showFieldMsg('var_environment', 'INFORMATION: Sandman will not run against this environment','info',true);
}
else{
g_form.hideFieldMsg('var_environment');
}
}

View solution in original post

14 REPLIES 14

Mark Stanger
Giga Sage

Is this running on a catalog item or a standard form in Service Portal?

This should work, but you need to supply the name of your field/variable instead of the 'WTest' variable name.  Try changing your script to this...

function onLoad() {
    var WTest = g_form.getValue('u_w_status');
    if (WTest == 'Awaiting') {
        // alert('What');
        g_form.showFieldMsg('u_w_status','Disclaimer .........' , 'info' , true);
    } 
}

i changed the script and removed row 2

if(g_form.getValue('u_w_status')== 'Awaiting') 

still same issue. 

Alert('') works fine though

Also, I'm seeing that these messages disappear if the field value changes so you'll need to make sure you re-show the field message each time the field changes.  You'll probably have better luck running this as an 'onChange' script against the 'u_w_status' field.

function onChange(control, oldValue, newValue, isLoading) {
    // Hide the field message if present
    g_form.hideFieldMsg('u_w_status', true);
    if(newValue == 'Awaiting') {
	// Re-show the field message
	g_form.showFieldMsg('u_w_status','Disclaimer .........' , 'info' , true);
    }
}