Skip to main content
Known Participant
May 2, 2024
Answered

How to set field format based on the field Name

  • May 2, 2024
  • 1 reply
  • 856 views

Hi All,

 

I am trying to automate the fillable field formating based on the field name, is it possible to set the field format based on the field format, I tried below script however it seems nothing changed and not showing any error.  However if i am not using the arr and use one field name it works. 

Any help much appreciated.

 

var arr = ['clm_bdate','di_date','ee_end_date_occ','ee_start_date_occ','ft_date','pt_date',' bdate_youngest', 'injury_date'];//date field names
for (var i = 0; i < this.numFields; i++) {
var A = this.getField(this.getNthFieldName(i));
if (arr.indexOf(A) >= 0) {
var cFormat = "mm/dd/yyyy";
A.setAction("Format", "AFDate_FormatEx(\""+cFormat+"\")");
A.setAction("Keystroke", "AFDate_KeystrokeEx(\""+cFormat+"\")");
}
}
this.getField("A").userName="Enter the Date in MM/DD/YYYY Format";

This topic has been closed for replies.
Correct answer try67

That's because A is not a field name. It's a variable that points to a Field object.

So it needs to be:

A.userName="Enter the Date in MM/DD/YYYY Format";

Also, you have to move that line up so it's inside the for-loop where A is defined.

1 reply

Bernd Alheit
Community Expert
May 2, 2024

Use the name of the field:

if (arr.indexOf(A.name) >= 0) {

Known Participant
May 2, 2024

Wow. That worked Bernd, Thank you so much,  Also the tooltip (userName) not getting update on the date field.

try67
try67Correct answer
Community Expert
May 2, 2024

That's because A is not a field name. It's a variable that points to a Field object.

So it needs to be:

A.userName="Enter the Date in MM/DD/YYYY Format";

Also, you have to move that line up so it's inside the for-loop where A is defined.