Expand my Community achievements bar.

SOLVED

Explain usage of "xfa.resolveNode" in laymen terms

Avatar

Level 6

I know this may be a novice question, but can someone please explain when/why xfa.resolveNode is used form design? Is it a form of shorthand to keep from referencing a parent subform?

Thanks in advance

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

There are a few situations when you need to resolve a node.

  1. When you are referencing an object that has the same name as other objects in the same container. In the hierarchy you would see TextField1[0], TextField1[1], TextField1[2], etc. The number in square brackets shows the instance number of each object. If in your script you want to reference TextField1[2], then you would need to resolve the node. This is a good reason to name objects as you drag them onto the form.
  2. You are referencing an object that is in an unnamed container/page/subform. The script needs to resolve the unnamed container in order to access the object inside. This would also apply if there are several containers with the same name (see 1 above). Again, another good reason to name containers as you go.
  3. If you are trying to reference a particular instance in a repeating object, then you would need to resolve that particular instance. There are several examples of this in the table samples here: http://assure.ly/lwQHm7.
  4. If your script is in an object in the main mages and you are referencing an object on the Master Page (or visa versa), then you would need to resolve the node.

There are the main times you would resolve the node. There may be more, but I can't think of any at this stage.

Resolving nodes is particular to JavaScript scripts and not FormCalc scripts.

SOM stands for Scripting Object Model. XFA forms have a number of models.

In a form the top object is XFA. This stands for XML Forms Architecture.

Under this are a number of child objects in a strict hierarchy. These are referred to as DOMs or Document Object Models. There are the:

  • XFA DOM. You would sometimes script against this model, for example, xfa.resolveNode().
  • Template DOM, which contains information about the form.
  • Data DOM, which holds information on the data structure and content.
  • Form DOM, which contains the merged Template DOM and Data DOM. Most of the scripting is done against the Form DOM.
  • Layout DOM, which contains page specific information for example xfa.layout.pageCount().

The Scripting Object Model (SOM) expressions allow you to access properties and methods.

This DRAFT form is a work in progress (I will eventually finish it): http://assure.ly/exTXaZ. The intention is to show how to build SOM expressions in different situations. At the moment it does not have any supporting text in it. Have a look at page 4 and over over the SOM expression.

I hope that helps,

Niall

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

Hi,

There are a few situations when you need to resolve a node.

  1. When you are referencing an object that has the same name as other objects in the same container. In the hierarchy you would see TextField1[0], TextField1[1], TextField1[2], etc. The number in square brackets shows the instance number of each object. If in your script you want to reference TextField1[2], then you would need to resolve the node. This is a good reason to name objects as you drag them onto the form.
  2. You are referencing an object that is in an unnamed container/page/subform. The script needs to resolve the unnamed container in order to access the object inside. This would also apply if there are several containers with the same name (see 1 above). Again, another good reason to name containers as you go.
  3. If you are trying to reference a particular instance in a repeating object, then you would need to resolve that particular instance. There are several examples of this in the table samples here: http://assure.ly/lwQHm7.
  4. If your script is in an object in the main mages and you are referencing an object on the Master Page (or visa versa), then you would need to resolve the node.

There are the main times you would resolve the node. There may be more, but I can't think of any at this stage.

Resolving nodes is particular to JavaScript scripts and not FormCalc scripts.

SOM stands for Scripting Object Model. XFA forms have a number of models.

In a form the top object is XFA. This stands for XML Forms Architecture.

Under this are a number of child objects in a strict hierarchy. These are referred to as DOMs or Document Object Models. There are the:

  • XFA DOM. You would sometimes script against this model, for example, xfa.resolveNode().
  • Template DOM, which contains information about the form.
  • Data DOM, which holds information on the data structure and content.
  • Form DOM, which contains the merged Template DOM and Data DOM. Most of the scripting is done against the Form DOM.
  • Layout DOM, which contains page specific information for example xfa.layout.pageCount().

The Scripting Object Model (SOM) expressions allow you to access properties and methods.

This DRAFT form is a work in progress (I will eventually finish it): http://assure.ly/exTXaZ. The intention is to show how to build SOM expressions in different situations. At the moment it does not have any supporting text in it. Have a look at page 4 and over over the SOM expression.

I hope that helps,

Niall

Avatar

Level 6

Thanks Niall! Very helpful info. I tried sending you a private email on a different subject (related toAD), but your mailbox is full. Do you have a different email address you can send me in a  private msg?

Avatar

Level 10

Hi,

You can catch us at http://www.assuredynamics.com.

I will try and get back to you as soon as I can, but will be out of the office a lot over the next few days.

Niall

Avatar

Former Community Member

Niall's information is correct but I do want to add a couple of comments. resolveNode is used in two situations:

1. xfa.resolveNode is in reality a search. The search will start with the current container and work its way UP the hierarchy tree. The 1st occurance found will be returned to you. So if I did xfa.resolveNode("TextField1"). The search will start in the context of where the script is executing and look UP the tree, until it finds a TextField1 node. Note this could be an expensive operation performance wise so use it wisely.

2. The value passed to resolveNode is a string.....so when dealing with fields that have occurance number [1] or unnamed subforms #subform both of those expressions have chars in them that javascript will interpret the wrong way (i.e. brackets are used for arrays). So by using a resolveNode('Som expression") you can referece these objects direclty (no search is needed as you are pointing to the particular object). For example xfa.resolveNode("form1.Page1.subform1.Object[1]").rawValue. In this case the som expression points to the direct object and no search is required. This notation is very helpful when using a for loop and affecting many objects with the same name (they woudl use occurance numbers) as you can manipulate the sting for your needs: i.e. xfa.resolveNode("form1.page1.subform1.Object[" + i + "]").rawValue where i is a variable that is set outside the expression.

Hope that makes sense.

Paul

Avatar

Level 6

pguerett,

Thank you for supplying additional information. Both you and Naill have been extremely helpful.

I guess I'm not sure when I'd ever use resolveNode considering I normally always name my fields and use either Absolute or Relative referencing. I take it, people are not physically typing out the full script....i.e. xfa.resolveNode("TextField1"), but  are using CTRL click or CTRL+ALT click and the resolveNode script/string is automatically added. I figure if you go the length of physically writing the resolveNode script, you might as well spend the time naming the fields and saving yourself the headache and possible performance issues.

I'm not sure how to use [" + i + "], but I know I've seen that expression before. I'll probably do some more research, unless you can provide a quick explanation.

Thanks again in advance.

Avatar

Former Community Member

The script you mention is simple manipulation of the string. In many cases (dynamic forms in particular) when you add a row ar subform, the fields are named the same as you are simply adding a new row then you have no choice. In those cases if you want to manipulate a column of fields (lets call them TextField1 inside of a subform called Row) then using an expression like this is very useful:

for (i=0;i<=Row.instanceManager.count;i++){

     xfa.resolveNode{"Row[" + i + "].TextField1").rawValue = some value

}

This for loop will lop through all of the row subforms (no matter how many you add or remove) and set the fields. Notice that we are simply manipulating the string that is being passed to resolveNode to give the syntax Row[occuranceNumber].TextField1.

Make sense?

Paul