I have a repeating table that can grow/shrink depending on how many entries a person needs. Each entry gets a value inputed in a "score" field. If all the scores are numbers, a simple sum of all the fields is calculated to get a number for total debit points. However, there are cases where an entry can be a "C", meaning that the score is Critical. In this case, the total debits sum should be blank or null.
The problem I run into is that the calculation will only work if the C "score" is on the first line of the repeating table. If it is on a second or subsequent line, then the debit score becomes 0. This is a problem because the total report score either reads as C if there is a critical debit or else 100 minus whatever the sum of the debits were. With my current set-up, a C entered on a second line of the table or later, may actually show up as a 100 for total report score because the total debit field was never set to blank or nullified.
Here is my code:
if (ViolationsTableSubform.ViolationsTable.ViolCorrSection.ViolationsText[*].DebitVal[*] == "C") then
$ = "";
What am I doing wrong?
I think that you would need to loop through the rows first to find a "C" and then process the if statement. Something along these lines...
var vScore = new Array();
var vCritical = 0;
var nRows = ViolationsTableSubform.ViolationsTable.ViolCorrSection.ViolationsText.instanceManager.count;
for (var i = 0; i < nRows; i++)
var oFld = xfa.resolveNode("ViolationsTableSubform.ViolationsTable.ViolCorrSection.ViolationsText[" + i + "]");
vScore = oFld.Debit Val.rawValue;
if (vScore == "C")
vCritical = 1;
if (vCritical == 1)
this.rawValue = "";
I'll be honest, I am merging a loop script that works for me (making rows hidden and visible), with your script. There is some tyding up to do!!
Hope that helps,
I have used the script you gave, but am unsure if it is working because my Total Sum field is set up to either subtract the total debits from 100 or enter a C depending on whether a sum calculation was done or a "" value was entered.
I have gone back to the books (JP Terry's "Creating Dynamic Forms with Adobe LiveCycle Designer") and think we can improve on things...
var oFields = xfa.resolveNodes("ViolationsText[*].DebitVal"); // looks to resolve the repeating rows (I think)
var nNodesLength = oFields.length; // assigns the number of rows to a variable
var sumTotal = 0; // this is a temporary holding variable for the total, during the loop
for (var i = 0; i < nNodesLength; i++) // this loops through as previous example
if (oFields.ViolationsText[i].resolveNode("DebitVal").rawValue == "C")
sumTotal = "";
i = nNodesLength; // stops the loop
sumTotal += oFields.ViolationsText[i].resolveNode("DebitVal").rawValue;
this.rawValue = sumTotal;
This would go in the calculate event of your Total Debit Points field. I would be amazed if it worked first time. I haven't run through LC. Give it a lash!! (a try!!)
I sure appreciate your help with this.
I plugged in the code as you wrote it, but it doesn't appear to be working. I tried selecting items w/ point values, but the debit total sum didn't calculate. I also tried selecting the item with the "C" and the debit total sum remained "0" instead of going to blank.
I am flying blind on this. Can you post the form or a version of the form with only the relevant table in it.
In addition, you can temporarily put in script which will throw values to the console:
console.println("sum total is: " + sumTotal);
This is useful to track different values or that they are working at all.
I am not surprised it didn't work first time. If you can post the file that would help!
Niall has answered my initial question offline (and a few others related to my form).
If it is helpful to anyone else what that solution was, let me know and I'll post the gist of it when I get time.
Thanks again Niall!