Behavior of g_form.showFieldMsg()

N_Y_1014
Tera Contributor

Thank you for your help.

I am working on the following three requirements.
All of them will be the behavior before the update.
-True/False field and a Date field.
-If the True/False field is false, the Date field should have a showFieldMsg and the showFieldMsg should not disappear when a value is entered.
-If the True/False field is true, showFieldMsg should disappear.

 

■ShowFieldMsg is displayed when True/False(checkbox) field is false and a value is entered in Date field (before update).

スクリーンショット 2023-11-07 234734.png

 

■When "True/False(checkbox)" field is set to "true", "showFieldMsg" in Date field is turned off (before update).

スクリーンショット 2023-11-07 234800.png

 

Initially, we determined that this could be achieved with a UI policy, so we created a UI policy with scripts.
However, the onCondition() script was able to dynamically show/hide showFieldMsg due to True/False changes, but when a Date value is entered, showFieldMsg disappears.

 

Therefore, we used a client script and created the following onChange() script.
With the client script, showFieldMsg did not disappear when a value was entered, but it was not possible to show/hide showFieldMsg dynamically by changing True/False.

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  // if (isLoading || newValue === '') {
  //    return;
  // }

   //Type appropriate comment here, and begin script below
	if(g_form.getValue('u_checkbox_test') === 'false'){
		g_form.showFieldMsg('u_date_test', 'date_description','info');
	
	}else if(g_form.getValue('u_checkbox_test') === 'true'){
		g_form.hideFieldMsg('u_date_test');
	}
}

 

 

I am not familiar with client scripting, so can this requirement be accomplished in client scripting?

Other ways to achieve this would be welcome.

 

Thank you in advance.

1 ACCEPTED SOLUTION

Peter Bodelier
Giga Sage

Hi @N_Y_1014 


You'll need to use this script twice.

Once triggered onchange on the checkbox, once triggered onChange on the date field.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

4 REPLIES 4

Peter Bodelier
Giga Sage

Hi @N_Y_1014 


You'll need to use this script twice.

Once triggered onchange on the checkbox, once triggered onChange on the date field.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

@Peter Bodelier 

@Anand Kumar P 

The requirement was achieved by creating onChange scripts for the checkbox and Date fields respectively in the client script.

In addition, by using oldValue, newValue, and isLoading, it was possible to dynamically show/hide the showFieldMsg even if the checkbox field's True/False value changes or the Date field's value is entered.

Thanks to both of you.

Anand Kumar P
Giga Patron
Giga Patron

Hi @N_Y_1014 ,
Try below script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (newValue === 'false') {
      g_form.showFieldMsg('u_date_test', 'This is a message for the Date field when checkbox is false', 'info');
   } else {
      g_form.hideFieldMsg('u_date_test');
   }
}


Thanks,

Anand 

Hi @N_Y_1014 ,
Working fine in my pdi

AnandKumarP_0-1699372525023.png

AnandKumarP_1-1699372554608.png

AnandKumarP_2-1699372581177.png

Please mark it as solution proposed and helpful if its serves your purpose.

Thanks,

Anand