XFA SOM Expression Generator

Have you ever had trouble figuring-out what the SOM expression is for a particular object which you’re trying to address within your script?

If so, here’s a tip that might come in handy the next time you’re stumped:

With the input focus (the “I” beam) set within the event you’re scripting on the Script Editor palette in Designer, hold-down the Control key and move your mouse over the canvas. Notice that as you hover over objects, the mouse pointer switches to a “V” cursor. If you click, the full SOM expression for the object you clicked will be automatically inserted into your script. But that’s not all! The generated SOM expression will be automatically formatted to work with your script’s language settings:

If you haven’t named the “page 1” subform and you pick an object on it, you’ll get the following code if your script’s language is FormCalc:

bc. form1.#subform[0].myField

If your script’s language is JavaScript, you’ll get the following code (for the same object):

bc. xfa.resolveNode(“form1.#subform[0].myField”)

Note that if you click on the object on which you’re scripting the event, “$” will be inserted for a FormCalc script and “this” will be inserted for a JavaScript script.

6 Responses to XFA SOM Expression Generator

  1. Dimitri Munkirs says:

    Nice tip Stefan! Very helpful.

  2. SteveX says:

    That’s funny – yesterday I was thinking about blogging the same thing. It’s a good tip.

  3. Arthur Maloney says:

    good tipI’m a UK er why don’t you let me pay the $1495 and I’ll join Developer Programme

  4. Arthur,You’re more than welcome to sign-up for Adobe’s Enterprise Developer Program. Please follow the link to learn more about it.

  5. smvo says:

    Stefan,This was the post more closely related to the resolvenodes method I could find in your blogs, so I will make my question here:In a form I have a subform named Test and a field named Test, too.I would like to get a reference for each of them, so I used this:xfa.resolveNodes(“xfa.form..Test”);However, I realizes I can only get the field object. If I take the field object from the form, I will get the subform object as expected.I also tried this:xfa.resolveNodes(“xfa.form..Test[*]”);But the problem is the same. does the method only returns one kind of object?Are there any workaround?Thank you

  6. smvo,I see what you’re trying to do. Unfortunately, I believe the “..” operator performs a depth-first search and returns the first match (or matches) it finds, which might explain why you’re never finding both objects.In fact, I think that the only way


    would return both the subform and the field is if they were siblings in the hierarchy.It’s difficult to tell without knowing what your form structure is but I’m going to guess that the “..” operator won’t be of much help.Is there a reason why you can’t cache a reference to each object in a script object variable (a variable declared in a script object)?If you absolutely need to go looking for the objects, then you may need to write a recursive function that performs the search starting from the root subform and looking into all child nodes. You can find something similar in the “ProcessAllFields” function defined in the sample form from my Process All Fields article.