I am creating a form somewhat similar to the Purchase Order example. When the user adds a line of the table to enter more information, the data that is returned to me retains the field names of the original table row. As I want to parse the data, each field has to have a unique name. Is there a way for the InstanceManager to add a count when the table row (subform) is repeated?
Thanks for any assistance.
Views
Replies
Total Likes
The addInstance() method actually clones the existing instance. So it is impossible to provide unique names for each row.
However you can refer your fields along with its parent subform.
For e.g if you write a code like this
Form1.page1._myInvoiceDetails.addInstance(1);
If you hve called this above line for several times (say 2 times), you will be having the hierarchy as follows:
Form1
Page1
myInvoceDetails
txtInvoiceNo
txtAmount
myInvoceDetails
txtInvoiceNo
txtAmount
myInvoceDetails
txtInvoiceNo
txtAmount
you can summarize the total as follows
FormCalc
Hi $Nith$,
Thank you for your reply. What is the FormCalc script that will summarize the total? I was hoping I could add a command to the addInstance() script line to insert a number on the click event. I expect I am not the only one who wishes to parse data gathered from the addInstance() function. Is there another command that would give me the information I am looking for while maintaining the simple form design offered by the InstanceManager?
JJ
Views
Replies
Total Likes
Just elaborating on Nith's example:
Form1
Page1
myInvoceDetails
txtInvoiceNo
txtAmount
myInvoceDetails
txtInvoiceNo
txtAmount
myInvoceDetails
txtInvoiceNo
txtAmount
Each time an instance is added a ne myInvoiveDetails section is added. To get to a specific txt Amount field occurance numbers (thay are 0 based). If I want the second occurance of txtAmount I woudl have to use the expression Form1.Page1.myInvoiceDetails[1].txtAmount.rawValue. If you want a total at the bottm of the repeating sections there are some nice FormCalc commands that can be used. In this case you couls use the command:
sum(Form1.Page1.myInvoicDetails[*].txtAmount.rawValue)
This will add all of the txtAmount fields together and return the sum. Note the use of the wildcard in teh occurance number. This technique is only available in FormCalc. If you wanted to use Javascript you woudl have to get the number of occurances, then write a for loop to loop through and add each occurance to get your sum....much easier in FormCalc!
When you are 1st doing this type of work on a complex form it is difficult to know what part of the expression is repeating. You can add a command to show you the somExpression. On the Enter event of the field in question just add the command: xfa.host.messagebox(this.somExpression). Now render your form and add a couple of instances. Now click on the field that has that code. A message will pop up showing you the somExpression of that field. Do a couple fo field so you can see the pattern. Once you have it, don't forget to remove that code ....it is for you teh developer to help write the script ...it is not for the end user.
Hope that helps
paul
Hi Paul,
That does help some. Thank you.
For the expression Form1.Page1.myInvoiceDetails[1].txtAmount.rawValue where does this go in the script? I used javascript for the addInstance, so does this expression go in the addInstance line or as a separate command? Sorry for the 'green' question. I am what I am.
JJ
Views
Replies
Total Likes
separate command ....
Paul
Views
Replies
Total Likes
addInstance() script will be written on the click event of one the button..
SUM(Form1.Page1.myInvoiceDetails[*].txtAmount.rawValue) is usually written on the Calculate event of your total field (usually text/numeric field)
Something make sense?
Nith
Views
Replies
Total Likes