Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Error checking code doesn't follow-through, assistance needed to make more "robust"

Avatar

Level 1

A table (Table "G") in a form I (said newbie) 'inherited' has the below script that is supposed to programmatically check fields prior to submission so the user can be directed to take corrective action(s). The table is optional unless either an amount is entered, or a radio button is selected.

SShot-0279.png


function oneLineTable(ERROR_MESSAGES, tableLetter, tableName){


   i=0;  // set the counter


   var TEXT;


   while (xfa.resolveNode(tableName + ".ROW" + "[" + i + "]")!=null){


      TABLE_ROW = tableName + ".ROW" + "[" + i + "]";


      J_AMOUNT = xfa.resolveNode(TABLE_ROW).J_FUNDS.rawValue;


      // The following switch handles differences in Tables C, E, F, and G


      switch (tableLetter) {


         case "C" : {


            TEXT = xfa.resolveNode(TABLE_ROW).MATCHINGGRANTNAME.rawValue;


            J_AMOUNT = xfa.resolveNode(TABLE_ROW).J_FUNDS.rawValue;


            break;


            }


         case "E" : {


            TEXT = xfa.resolveNode(TABLE_ROW).GRANTNAME.rawValue;


            J_AMOUNT = xfa.resolveNode(TABLE_ROW).J_FUNDS.rawValue;


            break;


            }


         case "F" : {


            TEXT = xfa.resolveNode(TABLE_ROW).RECIPIENT.rawValue;


            J_AMOUNT = xfa.resolveNode(TABLE_ROW).J_FUNDS.rawValue;


            break;


            }


         case "G" : { 


            TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OFFICER.rawValue;


            TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.REPLACEMENT_OFFICER.rawValue;


            TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.MATCH_SAL.rawValue;


            TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OVERTIME.rawValue;


            J_AMOUNT =  xfa.resolveNode(TABLE_ROW).J_FUNDS.rawValue;


            break;


            }


         }


        


      if (TEXT == null && J_AMOUNT != null) {


         ERROR_MESSAGES+="  ●  Enter Type/Amount on Table " + tableLetter + ", row "+ (i+1) + ".\u000d\u000a";


         }


      if ((J_AMOUNT == null || J_AMOUNT == 0) && TEXT != null) {


         ERROR_MESSAGES+="  ●  Enter a dollar value for Table " + tableLetter + ", row "+ (i+1) + ".\u000d\u000a";


         }


      if ((i != 0) && (J_AMOUNT == null && TEXT == null)) { // not first row


         ERROR_MESSAGES+="  ●  Row "+ (i+1) +" on Table " + tableLetter + " is empty.\u000d\u000a";


         }


      else {


         if ((xfa.resolveNode(tableName + ".ROW" + "[" + i+1 + "]")!=null) && // is first row and more than one row


            (J_AMOUNT == null  && TEXT == null)) { // and first row is empty


            ERROR_MESSAGES+="  ●  Row "+ (i+1) +" on Table " + tableLetter + " is empty.\u000d\u000a";


            }


         } // end else


      i+=1;


      }  // End While


   return (ERROR_MESSAGES);


} // End of function oneLineTable


The script is only performing correctly for the first of the four possible radio button selections ('Overtime'):

SShot-0285b.png

Here are a few examples of the error messages the script is currently incorrectly displaying.

The 2nd bullet item should say 'Enter a dollar value for Table G, row 2.' (instead it erroneously says 'Row 2 on Table G is empty.').

The 3rd bullet item shouldn't be displaying at all (instead it erroneously says 'Enter Type/Amount on Table G, row 4.').

SShot-0284.png

Please let me know how the script must be modified so that errors are correctly displayed for the remaining three possible amount entries and radio button selections. The other tables ('C', 'E', 'F') are okay and the entries are optional.

SShot-0278.png

PMB

Message was edited by: PMBInc, updated screenshot

Message was edited by: PMBInc, clarified/added more detail to problem description.

1 Accepted Solution

Avatar

Correct answer by
Level 1

Figured out that "||" (or) had to be inserted into the syntax, therefore this:


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.REPLACEMENT.rawValue;


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.MATCH_SAL.rawValue;


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OVERTIME.rawValue;


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OFFICER.rawValue;





...needed to be changed to this:


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.REPLACEMENT.rawValue || xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.MATCH_SAL.rawValue || xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OVERTIME.rawValue || xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OFFICER.rawValue;



Thank you.  PMBInc

View solution in original post

1 Reply

Avatar

Correct answer by
Level 1

Figured out that "||" (or) had to be inserted into the syntax, therefore this:


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.REPLACEMENT.rawValue;


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.MATCH_SAL.rawValue;


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OVERTIME.rawValue;


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OFFICER.rawValue;





...needed to be changed to this:


TEXT = xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.REPLACEMENT.rawValue || xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.MATCH_SAL.rawValue || xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OVERTIME.rawValue || xfa.resolveNode(TABLE_ROW).SALARYTYPE.rblSALARYTYPE.OFFICER.rawValue;



Thank you.  PMBInc