Highlighted

Instance Manager - how to reference?

xrum

10-12-2008

hi 🙂



i have a dynamic subform, which i am adding and deleting (users).



the subform has such information as name, address, phone etc.



is there a way for me to reference last (or second, or third) instance of that subform, and get the last address that has been added/deleted?



i can't seem to find a way to do it.



Thanks!

Replies

Highlighted

pguerett

10-12-2008

The innstanceManager has a count property which will give you how many occurances of that subform that exists. Also if you know which occurance that you want to look at you can address the field by using the full somExpression and giving the occurance number on the subform. Something like this:



form1.page1.dynamicSubformName[1].address.rawValue



Note that the [] will cause a problem in Javascript (they are used to indicate array elements) hence you need this syntax in javascript:



xfa.resolveNode("form1.page1.dynamicSubformName[1]").address.rawValue



Depending on where your code is runnning, if it is on a field level event you can get the occurance that the object is in by using this.parent.index



Hope this helps
Highlighted

xrum

10-12-2008

thanks!



when I do this:



xfa.resolveNode("form1.page1.dynamicSubformName[1]").address.rawValue



it works, but when i put in the count, instaed of 1



xfa.resolveNode("form1.page1.dynamicSubformName[dynamicSubFormName.instanceManager.count]").address.rawValue



i get "Malformed SOM expression" error....
Highlighted

pguerett

10-12-2008

The quotes signify a string. count needs to be a calculated value so you woudl do smething like this:



xfa.resolveNode("form1.page1.dynamicSubFormName[" + count + "]").address.rawValue



I assume count is a variable that contains the occurance that you want to test.
Highlighted

xrum

16-12-2008

that is correct....



but i still don't understand what i am doing wrong.....



this is my code now:



var myCount = userSub.instanceManager.count-1;



app.alert(xfa.resolveNode("form1.formPage.mainSub.userSub[myCount]").userName.rawValue);



i'm still getting the "Malformed SOM expression" error....
Highlighted

pguerett

16-12-2008

The issue is that myCount is not getting resolved beacuse it is inside of the quotes and is being interpretted as a string. I believe the expression should be:



app.alert(xfa.resolveNode("form1.formPage.mainSub.userSub[" + myCount + "]").userName.rawValue);
Highlighted

xrum

16-12-2008

yeay! it's working, thanks!



sorry, i didn't realize that " + myCount + " was the exact code i was to use 🙂



Thanks again!