Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

instanceManager subform instance referencing?

Not applicable
Seems like you cant use a variable to call an instance?

Asuming I have x instances of .detail1 below & need to do something to them all:



var agendas = 0;

xfa.resolveNode("form1.Sheet1.detail1[agenda].Button2").presence="invisible";



if I replace the [agenda] with 0 it works. I'm trying to make a for loop that crawls through a number of instances with no luck. Any thoughts?



replace with an [*] and acrobat crashes!
11 Replies
Not applicable
Should work, has done it myself a lots of times... but remember to but agenda in correct syntax.

var agenda = 0;

xfa.resolveNode("form1.Sheet1.detail1["+agenda+"].Button2").presence = "invisible";
Not applicable
aha - that's a syntax I've not seen before. thanks. What are the + marks for & why the quotes?



thanks,

-jamie
Not applicable
follow up: first time I've tried to write a FOR loop. Can you spot my mistake?



for (var i=0; i<=Sheet1.formType.body2.ExpandingMemo.details.detail1.instanceManager.count; i++;)

{

xfa.resolveNode("Sheet1.formType.body2.ExpandingMemo.details.detail1["+i+"].Button2").presence="invisible";

};



well, the smiley face is supposed to be a ; and a )



Oh - nevermind I found it - the extra ; after the i++ was the problem.
Ryan_Lunka
Level 5
Level 5
FYI - The syntax you are unfamiliar with is a bit tricky at first. The resolveNode function evaluates a string and tries to see if there is a form object to match it. When your string is...



"Form.subForm.Table.Row[x].Cell1"



The script is looking for a Row with an index of "x", which technically does not exist. By breaking the string and concatenating in the variable (at runtime, whatever value that variable contains - in your case, the loop increment) to that string. LiveCycle will evaluate it as such.



Hope that helped explain it a little.



Ryan D. Lunka

Cardinal Solutions Group

rlunka@cardinalsolutions.com
Not applicable
Ryan, thanks for the explanation. Makes sense.
Not applicable
So, then the follow-up follow-up question:



I have two of these FOR-Loops in a row, each of which works independantly, but when I have the two of them on the "Click" event of the button they dont work.



Any guesses why only the first one runs?



for (var i=0; i<=form1.Sheet1.formType.body2.ExpandingMemo.details.detail1.instanceManager.count; i++){

xfa.resolveNode("form1.Sheet1.formType.body2.ExpandingMemo.details.detail1["+i+"].Button2").presence="invisible"

};



for (var k=0; k<=form1.Sheet1.ImageSection.detail.instanceManager.count; k++){

xfa.resolveNode("form1.Sheet1.ImageSection.detail["+k+"].deleteButton").presence="invisible"

};
pguerett
Level 10
Level 10
Any errors in the javscript console?
Not applicable
No obvious syntax error in your code (although it's not the easiest to find always). But why do you put the ; after the closing bracket } ?

Usually these kind of errors happen when your code generates an error in the first loop, thereby Pauls question. Since you don't seem all familiar with the Designer/pdf development process, check if you have enabled the option to show javascript console on errors in the Reader. It's a bit hidden in the settings for Acrobat Reader but it helps out a lot in these cases to see if something goes wrong.
Not applicable
Whoa - that's the console I kept looking for in Livecycle...



23:XFA:form1[0]:#pageSet[0]:Page1[0]:logoStuff[0]:calculate

xfa.resolveNode("form1.Sheet1.formType.body2.ExpandingMemo.details.detail1[" + i + "].Button2") has no properties

7:XFA:form1[0]:Sheet1[0]:formOptions[0]:lockdown[0]:click



So it is the first loop causing the error, but its doing what its supposed to first...



I tried again without the semi-colon ; after the brackets. No change. Was just copying what I saw in the Order Form sample file...
Not applicable
Regular programming looks like this:

for(.....){

var demo = "Syntax";

}

Correct syntax is always nice no matter if it's always necessary in this javascript world we live in or not... your code wouldn't compile in a language that had better compilers than the javascript compiler found in the designer but it's pretty much acceptable code in javascript.



Your problem then. You should have multiple instances of the subform detail1 according to your code. Do you? And when does it generate the error, at i=1 or later on? Looks like a classic index error, your subform might very well be outside the index... or the button is missing that it's referring to?



I see that you have a count of the instances, but can you verify that the count is correct?
Not applicable
Sture,



management has removed the button that this script was on... bullet dodged for now. Thanks for your help.



Sounds like you're on the right debugging track. I figured I was probably OK initiallizing the variable to 0 and then having the test at <= as I cant imagine that there would ever be negative instances of a subform?