Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

ResolveNode/Find node?

Avatar

Level 6
Hello!



I was wondering if there is a function to find a field by name in a PDF.

I already saw a lot of examples using Resolvenode, however, these examples always used the path to the node (page.subform.etc). Because I don´t know where the field will be or even if the fields really exists, I would like to search for it easily. The only solution I had found was to interact through all the nodes on each page, but this seems not very efficient.



Thank you
17 Replies

Avatar

Former Community Member
Say for example the field is called MyTestField, you can use resolveNode() to search for it like so:



xfa.resolveNode("MyTestField");



This is much less efficient than drilling down a bit and looking in a specific section, but if you have no idea where the node could be then you don't have much choice. This will start from the top and search the DOM node by node until it finds MyTestField.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
I have a question to go along with this. I'm still not clear on how to get to a certain field in one of the instances of a subform. For example



There are four instances of a subform called mySubForm. In each of the subforms there are three fields: Field1, Field2, Field3. How do I get or set the value for "Field2" in the second instance of the subform?



The occurances of the subform is defined in the Repeat Subform for each Data Item > Initial Count = 4.

Avatar

Former Community Member
So there are a few ways you can do this:



In JavaScript:



form.somToParentSubForm.resolveNode("mySubForm[1]").Field2.rawValue = "test";



or



var nodeList = form.somToParentSubForm.resolveNodes("mySubForm[*]");

nodeList.item(1).Field2.rawValue = "test";



In FormCalc you could go direct:



form.somToParentSubForm.mySubForm[1].Field2.rawValue = "test";



Basically, '[' and ']' can't be used in a JavaScript expression so you use resolveNode in JavaScript to access the specific instance of the subform you want.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
I got the first two JavaScript examples to work. Thanks.



I held down the control key then clicked on the field I wanted to access to get the following path.



xfa.resolveNode("form1.mainPage.mySubForm.Field2")



Then I made some changes to some of this line as in,



xfa.resolveNode("form1.mainPage.mySubForm[1].Field2");



I couldn't understand why it wasn't working when I put in the instance number (mySubForm[1]). It seemed logical to me. It looks like I have to isolate the instance inside the parenthesis first then access the field outside the parenthesis.

Avatar

Level 6
Chris,



Despite it seems simple, I can´t see xfa.resolveNode("MyTestField"); working... I always get a null object/value. I´m using Acrobat Professional 7.0.5. Can it be a version problem?



Thank you

Avatar

Former Community Member
Shouldn't be a version problem. It seems to work here for me. Can you put your form online somewhere that I can take a quick look at it?



Chris

Adobe Enterprise Developer Support

Avatar

Level 6
Hi,



Sorry, I just work inside an Intranet...

The form where I tested is very simple: two subforms with a text field in the second one. Then I use this code at doc ready event of the main form:



var c = xfa.resolveNode("TextField1");

app.alert(c); //Gets null ....



Thank you!

Avatar

Former Community Member
Ok, try this form then. Does it work for you? It does for me. What's different between my form and yours?



Chris

Adobe Enterprise Developer Support

Avatar

Level 6
Hi,



It works... However, if I had a subform from my Designer... it will not work again. I´m using designer 7.0. However, I tried in Designer 7,1 and the problem persist...



When I place a new subform at the form the subform gets call SubForm1 and not (untitled Subform). Can be this a clue for the error?



Thank you

Avatar

Level 6
Ok,



I got it. If you rename the subForm where the text field is, you get the null value. How come?

Avatar

Former Community Member
I see what you mean. It "should" work, but it obviously isn't. I'm looking into it.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Ok, apparently resolveNode() works a little different from what I thought, and I just learned something new, so thanks :d



The way resolveNode() works is it will start from the node that it is called from. So xfa.resolveNode() starts from top level. Whereas, xfa.form.formName.subForm1.subForm2.resolveNode() would start from the subForm2. At this point it will look at all nodes that share the same parent as the one from which it is called from. If it doesn't find what it's looking for it will then traverse UP the tree to look for it (yes, UP, not down). That's why it doesn't find your TextField1, because it is lower in the tree than the top level...



So at this point you may react as I did and say something like "Wow, searching UP a tree is $@#%$# useless". Well, it might actually be useful in some circumstances, and luckily there is a notation you can use to make it search down the tree too. If you do something like:



xfa.resolveNode("form1..TextField1");



This tells it to start at form1 (you'd rename this to whatever you top level form node is called) and the .. says look DOWN and find TextField1. So if you use that on your form you will be able to find TextField1 regardless of where it is on the form.



Chris

Adobe Enterprise Developer

Avatar

Former Community Member
Thanks for the new info. This discussion is really helping. I have been playing around with this in various ways and have come up with several ways to do basically the same thing.



//This works.

form1.mainPage.resolveNode("mySubForm[1]").Field3.rawValue = "Yes";



//This works.

var nodeList = form1.mainPage.resolveNodes("mySubForm[*]");

nodeList.item(1).Field3.rawValue = "Yes";



//This works.

var myFld = xfa.resolveNode("form1..mySubForm[1].Field3");

myFld.rawValue = "Yes";



//This works.

xfa.resolveNode("form1..mySubForm[1]").Field3.rawValue = "Yes";



Here is something else.

I was even trying to get a user response to work in the following example.



var mySubF = xfa.host.response("Which Subform instance?", "", "");

xfa.resolveNode("form1..mySubForm[" + mySubF + "]").myFld3.rawValue = myV;



So I can get the user to key in a number in the response dialog that come up specifying which subform use. But how do I combine a response with part of the field name as in Field 1, 2, or 3. So if the user keys in 3 then 3 is put together with Field to get Field3?

Avatar

Former Community Member
Let's say the response is stored in a variable named myFieldNum it would look like:



form1.mainPage.resolveNode("mySubForm[1].Field" + myFieldNum).rawValue = "Test";



Just remember, resolveNode searches through nodes in the DOM looking for the one you want. It's not great for performance. So only use it when you need to, and whenever possible use it such that it will start looking in a position where it will find the node you want as soon as possible.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Part of the confusion I have been having is coming from Acrobat JavaScripting where the field names are always in quotes and they aren't using JavaScript for Designer. By the way what is this brand of JavaScript really called? Is it xfa JavaScript?



Thanks for all the help on increasing my understanding. You folks at Adobe are great job.