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:
form1.#subform[0].myField
If your script’s language is JavaScript, you’ll get the following code (for the same object):
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.
Posted by Stefan Cameron on June 5th, 2006
Filed under Script Editor,Scripting
Both comments and pings are currently closed.
Nice tip Stefan! Very helpful.
That’s funny – yesterday I was thinking about blogging the same thing. It’s a good tip.
good tip
I’m a UK er why don’t you let me pay the $1495 and I’ll join Developer Programme
Arthur,
You’re more than welcome to sign-up for Adobe’s Enterprise Developer Program. Please follow the link to learn more about it.
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
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.
Hi Stefan,
I am adressing a subform and put this in a variable. In my if statement I want to access the variable and traverse down to the textfield. How to dot his in FormCalc.
var contentX = Message.content;
if( $.rawValue == 1) then
contentX.option.presence = “hidden”
endif
The contentX.option.presence does not work.
option is a second subform.
Vandana,
I’m afraid I’m going to need a little more context before I can take a guess at what’s going wrong. I can’t make sense of the script you posted.
Has this SOM hierarchy changed for LiveCycle ES and Acrobat Pro 9?
No matter what combination I try I keep getting “invalid row” on my import using importTextData
When I do the ctrl-shift V it gives me: form1.frmTask.task
but when I put that in as my column header in my tabbed delimited file I still get invalid row
Any thoughts?
Paul
Paul Wesson,
SOM expressions haven’t changed. Perhaps you need the fully-qualified SOM expression, rather than the abbreviated form you get when you use [Ctrl + Shift + {click}]?
Based on “form1.frmTask.task”, the fully-qualified version could be “form1[0].frmTask[0].task[0]”, assuming the first instance of each object was being referenced.
My AcroForm Field Name Generator script could be used to determine the definitive fully-qualified SOM expression if you aren’t certain of what it might be.