Skip navigation
Currently Being Moderated

Referencing and comparing strings in different dynamic subforms with For loop

Apr 3, 2012 4:32 PM

I have created a form that I almost have working and I'm hoping someone can help me.

 

We have eight billing teams in our company and each team works anywhere from 1 - 4 different clients. The form is used to track, per Billing Rep, the number of items of mail that each billing r5ep works each day. What I'm needing to add at the bottom is a subform that tracks the totals by client. So I'm trying to get the form to loop through all of the existing subforms (and the subforms within them) and compare a cell int he bottom subform to a cell in the other subforms, which are dynamically added, and then total ONLY those items. My script however is not working.

 

What I have now is:

 

var repCount = form1.P1._rep.count

var itemCount = form1.P1.rep._ItemSet.count

 

for (x=0; x<repCount; x++)

{

     for (i=0; i<itemCount; i++)

     {

          if(clientName.rawValue == P1.rep[x].ItemSet[i].client.rawValue)

          {

          this.rawValue = this.rawValue + P1.rep[x].ItemSet[i].corresp.rawValue;

          }

     }

}

 

It seems like this should work but I'm getting the following error:

 

P1.rep[x] is undefined


So what it looks like is I'm missing is the proper way to reference the objects in these subforms.

 

I changed the script since then to this:

 

var repCount = form1.P1._rep.count

var itemCount = form1.P1.rep._ItemSet.count

 

for (var x=0; x < repCount; x++)

{

    for (var i=0; i < itemCount; i++)   

    {

        if (P1.resolveNode("rep["+x+"].ItemSet["+i+"]").client.rawValue == clientName.rawValue);

        {

        this.rawValue = this.rawValue + form1.P1.resolveNode("rep["+x+"].ItemSet["+i+"]").corresp.rawValue;

        }

    }

}

 

And this doesn't generate errors, but rather, it puts the same total in both fields that appear at the bottom.

 

The form is here: https://acrobat.com/#d=20gWXZ4sBm4OPV6oO76zSg

If someone could take a look at it I would be so grateful.

 

Thanks,

Jo

 
Replies
  • Currently Being Moderated
    Apr 4, 2012 3:24 AM   in reply to joflo723

    Hi Jo,

     

    Having looked at the code and it appears that the problem is caused by this line

     

    this.rawValue = this.rawValue + myTemp2.corresp.rawValue;

     

    The 'this' object is referring to all the instances of the correspTotal for that table and therefore everytime it is run it is adding the totals to all of the fields, I think this needs to be changed to refer to the specific instance of the correspTotal field you are wanting to add the value to.

     

    I am still investigating how to do this but I thought I would let you know my finding so that you would be able to investigate.

     

    Hope this helps

     

    Malcolm

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 4:19 AM   in reply to joflo723

    HI,

     

    I have been able to get something similar to what you wanted working, I have had to change it to run on a button click, this is due to the calculation actually running multiple times and therefore creating incorrect answers in the totals table.

     

    the file is here ( sorry if I messed up the layout a bit) - https://acrobat.com/#d=BTu6GrrnWBKM01*91Q0txg

     

    Here is the changed code so that you can see easily what has been done ( and also for anyone else who has a similar issue)

     

     

    var repCount = form1.P1._rep.count;

    var itemCount = form1.P1.rep._ItemSet.count;

     

    // get the total number of different clients

    var allClientsCount = this.parent.parent._clientTotals.count;

    // create an array to make sure that we reset the total to zero

    // but only on the first of each client.

    var firstRun = new Array();

    for ( var k = 0; k < allClientsCount; k++)

    {

        firstRun.push (true);

    }

     

    for (x=0; x < repCount; x++)

    {

        for (i=0; i < itemCount; i++)   

        {

            var tempTotals = null;

           

            // I broke the resolveNodes up just to make it easier to follow.

            var myTemp = xfa.resolveNode( "P1.rep["+x+"]");

            var myTemp2 = xfa.resolveNode ( myTemp.somExpression + ".ItemSet["+i+"]");

            var myTempVar = myTemp2.client.rawValue;

           

            // loop for each possible client and add to the total for that client

            for ( var j = 0; j < allClientsCount; j++)

            {

                var tempTotal = this.parent.parent.resolveNode("clientTotals["+j+"]");

                if (tempTotal.clientName.rawValue == myTempVar )

                {

                    // if we have not added to this specific client before, start with the first entry

                    if ( firstRun[j] == true)

                    {

                        tempTotal.correspTotal.rawValue = myTemp2.corresp.rawValue;

                        // set the array to say that this value has been reset

                        // and therefore every other value should be added on

                        firstRun[j] = false;

                    }

                    else

                    {

                        tempTotal.correspTotal.rawValue += myTemp2.corresp.rawValue;

                    }

                }

            }

        }

    }

     

    Hopefully this will be useful to you in your final solution.

     

    Malcolm

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 5:52 AM   in reply to joflo723

    Hi Jo,

     

    As the myTemp2.hcfaTotal, is the field in the 'P1.rep[x]' part of the form it looks like it should just be

     

    myTemp2.hcfa.rawValue;

     

    And therefore the IF statement in my code about should look something like this

     

    if ( firstRun[j] == true)

                    {

                        tempTotal.correspTotal.rawValue = myTemp2.corresp.rawValue;

                        tempTotal.hcfaTotal.rawValue = myTemp2.hcfa.rawValue

                        firstRun[j] = false;

                    }

                    else

                    {

                        tempTotal.correspTotal.rawValue += myTemp2.corresp.rawValue;

                        tempTotal.hcfaTotal.rawValue = myTemp2.hcfa.rawValue

                    }

     

    Hope this helps

     

    Malcolm

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points