Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Scan table's columns for empty cells

Avatar

Level 2

I have prepared a form that will do the following (please bear with me for the description):

The form opens with a 10-row table.  The user must enter ratings (from 0 to 10) in one of the table's columns.  Once the user enters all ten ratings, he or she must then click a button to enable the rest of the form (which is hidden).  What I am trying to do is, after the button is clicked, scan the table to make sure the entire column has been filled in with a number.  If the column has been completed then a second page will appear.  If a cell in the column has been left blank, then I want a prompt to appear and tell the user which cell is empty.  I have been able to get it to work using the following code:

//This code is under the 'click' event.

if (decisionMatrix.dMTable.Row4.rating.rawValue == null)
{
//Displays a warning prompt that states form is incomplete

   xfa.host.messageBox("Form incomplete.  Please complete the background field.", "Warning", 3);
}
else
{
// Allow the user to save the current state of the form and enable the second part of form.
app.execMenuItem("SaveAs");
}

The problem with the above method is that it only checks the cell in Row4.  I would have to add more code for the 9 additional rows in the table and for each message box, telling the user which field to fill in.  Is there a more efficient way to do this?  A switch-case statement perhaps?

I have also considered scanning the entire column at once and just using a general message box for the table, using the following code:

if (decisionMatrix.dMTable.Row[*].rating.rawValue == null)

{
//Displays a warning prompt that states form is incomplete

    xfa.host.messageBox("Form incomplete.  Please complete all rating fields.", "Warning", 3);
}

...

But it does not seem to be working.  Any assistance is appreciated.  Thanks.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

The attached contains a table with 10 rows and 3 columns (a_, b_, and c_). Clicking the "Continue" button calls the click event which iterates over the table looking for nulls in each column by row. The "ratingMissing" flag controls the visibility of page 2.

// form1.page1.subform1.continueBtn::click - (JavaScript, client)


var ratingMissing = false;


for (var i=0; i < 10; i++) {

  var row = i + 1;

  if (xfa.resolveNode("form1.page1.subform1.table.row[" + i + "].a_").rawValue == null) {

    xfa.host.messageBox("A is missing in row " + row);

    ratingMissing = true;

  }

  if (xfa.resolveNode("form1.page1.subform1.table.row[" + i + "].b_").rawValue == null) {

    xfa.host.messageBox("B is missing in row " + row);

    ratingMissing = true;

  }

  if (xfa.resolveNode("form1.page1.subform1.table.row[" + i + "].c_").rawValue == null) {

    xfa.host.messageBox("C is missing in row " + row);

    ratingMissing = true;

  }

}


if (ratingMissing == false) {

  form1.page2.presence = "visible";

}

else {

  form1.page2.presence = "hidden";

}

Steve

View solution in original post

1 Reply

Avatar

Correct answer by
Former Community Member

The attached contains a table with 10 rows and 3 columns (a_, b_, and c_). Clicking the "Continue" button calls the click event which iterates over the table looking for nulls in each column by row. The "ratingMissing" flag controls the visibility of page 2.

// form1.page1.subform1.continueBtn::click - (JavaScript, client)


var ratingMissing = false;


for (var i=0; i < 10; i++) {

  var row = i + 1;

  if (xfa.resolveNode("form1.page1.subform1.table.row[" + i + "].a_").rawValue == null) {

    xfa.host.messageBox("A is missing in row " + row);

    ratingMissing = true;

  }

  if (xfa.resolveNode("form1.page1.subform1.table.row[" + i + "].b_").rawValue == null) {

    xfa.host.messageBox("B is missing in row " + row);

    ratingMissing = true;

  }

  if (xfa.resolveNode("form1.page1.subform1.table.row[" + i + "].c_").rawValue == null) {

    xfa.host.messageBox("C is missing in row " + row);

    ratingMissing = true;

  }

}


if (ratingMissing == false) {

  form1.page2.presence = "visible";

}

else {

  form1.page2.presence = "hidden";

}

Steve

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----