Expand my Community achievements bar.

Annual Leave Form Problems - Calculations change after saving

Avatar

Former Community Member

Hello,

My colleague is having a nightmare with her form and cannot see where she is going wrong.

The problem is that on saving the form the calculated values change.

All seems well up until we get to six rows of the repeating subform.  The calculations work until you save the (reader enabled form), close and then open.

It goes from this:

before.GIF

To this:

after.GIF

The scritping is placed in the hidden second row.  All the other fields after this have been generated as a repeating subform.

Here is the script.

if (Row2.status.rawValue == 1 & Row2.authorised.rawValue == 2)
{
form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2.balance.rawValue = Row1.balance.rawValue-Row2.daysappliedfor.rawValue;
}
else
if (Row2.authorised.rawValue == 2)
{
var numberOfRows = xfa.resolveNodes("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2[*]").length;
var numberOfRowss = xfa.resolveNodes("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row1[*]").length;
var numberOfRowsss = xfa.resolveNodes("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2[*]").length;
var currentRow;
var minusRow;
var otherRow;
var a
var b
var c
var d
var e
var f

for(var i = 0; i <= numberOfRows - 1; i++)
for(var k = 0; k <= numberOfRowss - 1; k++)
for(var j = 0; j <= numberOfRowsss - 2; j++)
{
currentRow = xfa.resolveNode("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2[" + i + "]");
otherRow = xfa.resolveNode("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row1[" + k + "]");
minusRow = xfa.resolveNode ("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2[" + j + "]");
a = currentRow.daysappliedfor;         
b = currentRow.balance;
c = currentRow.authorised;
d = currentRow.status;
e = minusRow.balance;
f = otherRow.balance;
e.rawValue-a.rawValue;

}}
if (Row2.status.rawValue == 1 & Row2.authorised.rawValue == 3)
{
form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2.balance.rawValue = Row1.balance.rawValue;
}
else
if (Row2.authorised.rawValue == 3)
{
var numberOfRows3 = xfa.resolveNodes("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2[*]").length;
var numberOfRowss3 = xfa.resolveNodes("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row1[*]").length;
var numberOfRowsss3 = xfa.resolveNodes("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2[*]").length;
var currentRow3;
var minusRow3;
var otherRow3;
var a3
var b3
var c3
var d3
var e3
var f3

for(var i3 = 0; i3 <= numberOfRows3 - 1; i3++)
for(var k3 = 0; k3 <= numberOfRowss3 - 1; k3++)
for(var j3 = 0; j3 <= numberOfRowsss3 - 2; j3++)
{
currentRow3 = xfa.resolveNode("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2[" + i3 + "]");
otherRow3 = xfa.resolveNode("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row1[" + k3 + "]");
minusRow3 = xfa.resolveNode ("form1.flowSubForm.page1.part1.part1FlowContainer.questionContainer1.Table1.Row2[" + j3 + "]");
a3 = currentRow3.daysappliedfor;         
b3 = currentRow3.balance;
c3 = currentRow3.authorised;
d3 = currentRow3.status;
e3 = minusRow3.balance;
f3 = otherRow3.balance;
e3.rawValue-0;
}}

Given the nature of the problem we think it may something with either a rogue initialize event affecting the calculation or a faulty resolve node calculation.

Grateful for any help.

3 Replies

Avatar

Level 7

if (Row2.status.rawValue == 1 & Row2.authorised.rawValue == 2)

if (Row2.status.rawValue == 1 & Row2.authorised.rawValue == 3)

should be && not &

also

Even though javascript is loosely typed, when dealing with DDLs, I think it is prudent (good practice)  to assume a string type of value like "2":

Also, I haven't really followed the script through, but it seems you there may be a much easier way to accomplish what you've set out to do. Not knowing what that is exactly, I can't offer a solution. But, it looks like you're trying to have a single script shoulder the entire form. Me, personally, I would place individual scripts on the fields--the scope is much easier to deal with and doesn't require all those loops.and resolveNode() functions.

Cheers,

Stephen

Avatar

Level 7

In order to be of further assistance

  • a screen shot the expanded (expand all the levels so all objects a revealed) in the hierarchy. pallet 
  • an explanation of the objective for the script
  • what is the exact object and event for the current script

Good luck!

Stephen

Message was edited by: kingphysh

Avatar

Level 7

Sorry, I keep seeing issues--

for(var i = 0; i <= numberOfRows - 1; i++)

for(var k = 0; k <= numberOfRowss - 1; k++)

for(var j = 0; j <= numberOfRowsss - 2; j++)

These appear to be nested loops. For loops need brackets.

for(var i = 0; i <= numberOfRows - 1; i++){

for(var k = 0; k <= numberOfRowss - 1; k++){

for(var j = 0; j <= numberOfRowsss - 2; j++)

     {do something;}

}

}