Hide & Display Info Message From True/False Field

PB20201617
Kilo Contributor

There are workarounds to this, but none of them are exactly what I am looking to accomplish & I more or less want to know if this can be done at this point because I can't seem to figure it out.

  • I want a True/False field to control an info message being displayed on the form.
  • If the field is set to true, the message should show & if the field is set to false, the message should be removed.
  • There should not be a limit to the number of times the message can be shown / removed without reloading the form.
  • I want the message to be displayed at the top of the form opposed to below the field.
  • The message should be able to have HTML, which shouldn't be an issue for info message but becomes an issue if I go the field message route.
  • I do not want to clear all messages being displayed on the form when the value is set to false, rather only remove the message that is being controlled by the true/false field.

I've tried using both an onChange Client Script & a UI policy, but both seem to give me the same result. In the script below, I have a condition on the UI policy I am using set to run when my field is set to true. Additionally Isolate script is set to false.

Execute if true:

function onCondition() {
    g_form.addInfoMessage('Please note this info', 'myInfoMessage');
}

Execute if false:

function onCondition() {
	$j('#myInfoMessage').remove();
}

This almost works & gets very close to what I am looking for, however it acts very odd & will initially display the message when set to true, will remove the message when set to false, and finally will do nothing when set to true again.


I tried to get creative & thought maybe if I utilize the scratchpad to hold a count, then change the name of the message each time that I may be able to get different results. Sadly this was not the case & the code below does the same thing as the code above, however the alert does count up indicating to me that my script logic at the least appears to be working

Execute if true:

function onCondition() {
	if (g_scratchpad.message == null || g_scratchpad.message == ''){
		g_scratchpad.message = 1;
	} else {
		var num = g_scratchpad.message;		
		g_scratchpad.message = num + 1;
		alert(num);
	}
	var messageName = 'myInfoMessage' + g_scratchpad.message;
    g_form.addInfoMessage('Please note this info', messageName);
}

Execute if false:

function onCondition() {
	var messageName = '#myInfoMessage' + g_scratchpad.message;
    $j(messageName).remove();
}

 

Additionally with the code described above, I found that the message can be shown -> removed -> re-shown if I set the field to true, then click the X on the info message to remove it, then set the field to false (nothing happens as the info message was already removed with the X), and finally set the field to true again. I suspect this is similar logic to g_form.clearMessages() which I'm trying to avoid using, but none the less I found it interesting.

1 ACCEPTED SOLUTION

Hello,

Here is the code. Works for me should work for you:-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var know=g_form.getValue('knowledge');
g_form.addInfoMessage('Please note this info', 'myInfoMessage');

if(know=='true')
{

$j('#myInfoMessage').show('');

}
else
{
$j('#myInfoMessage').hide('');


}

}

 

Please mark the answer as correct.

Thanks.

 

View solution in original post

11 REPLIES 11

KS13
Tera Contributor

Thank you for your assistance!

Community Alums
Not applicable

Would you mind sharing how you got the hyperlinks to work in Field Message?I have been looking for that solution and haven't found it yet.