Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

In LiveCycle/Forms Designer PDF, script breaks if 'resolveNode' is used on path that doesn't exist (null). How to remove paths that are no longer valid from scripts in entire form?

Avatar

Level 4

It looks like the 'LiveCycle' community is archived so I posted this here. If this should go elsewhere please let me know.

I inherited a LiveCycle PDF that has about 1,600 instances of 'resolveNode' in the scripts used throughout the form.  In debugging the form I've noticed that many script events are failing prematurely and silently.  It seems to me that this is happening because 'resolveNode' is being used on som expressions/paths that no longer exist within the document and are returning 'null'.

 

Is there a way to make the form continue running scripts if 'resolveNode' is used on a null path?  

If not, is there an easy way to find all the instances of 'resolveNode' that are null?  The only (sort of) reasonable thing I've thought of is extracting all 1,600 resolveNode expressions, putting them in an array, and using something like the below function to make a list of every one with a null value, then removing those lines manually. Is there any other option?

 

const fieldsArray = ["form1.Page1.field1","form1.Page1.field2"];

for (i = 0; i < fieldsArray.length; i++) {
	if (xfa.resolveNode(fieldsArray[i]) == null){		
		console.println("Null field: " + fieldsArray[i]);
	}
} 

 


Edit: Also worth mentioning, this is the type of script that is failing prematurely. I'm not sure why trying to set the access property of a null field would result in the rest of the script breaking, but that's the behavior I'm seeing:

//This script is bound to the click event of a checkbox
this.resolveNode("form1.Page1.field1").access = "readOnly"; //For this example, this field exists and the access property is set properly.
this.resolveNode("form1.Page1.field2").access = "readOnly"; //This field does NOT exist and returns null. As a result the following lines of this script do not run
this.resolveNode("form1.Page1.field3").access = "readOnly"; //This line does not run due to the null issue in the line above



1 Accepted Solution

Avatar

Correct answer by
Level 10

You can use the resolveNodes() method, to create a filtered list of suitable nodes by searching for classNames and other properties. So you'll avoid the null-problem completely. 

 

// Filter all field nodes that are not buttons.
var fieldsArray = xfa.form.form1.resolveNodes('#field.[ui.oneOfChild.className ne "button"]');
for (i = 0; i < fieldsArray.length; i++) {
    // add your to be executed …     
    fieldsArray.item(i).presence = "hidden";
} 

 

 

 

// Filter all field nodes.
var fieldsArray = xfa.form.form1.resolveNodes('#field[*]');
for (i = 0; i < fieldsArray.length; i++) {
    // add your to be executed …     
    fieldsArray.item(i).presence = "hidden";
} 

 

 

// Filter all field with a particular name part.
var fieldsArray = xfa.form.form1.resolveNodes('#field.[At($.name, "field") gt 0]');
for (i = 0; i < fieldsArray.length; i++) {
    // add your to be executed …     
    fieldsArray.item(i).presence = "hidden";
} 

View solution in original post

4 Replies

Avatar

Community Advisor

You need to delete or comment on these lines which are not needed now.

or you can add a null check on them.

Since they don't exist on the form now so better to delete their reference in the script.

if(field_Xpath){

 

}

Avatar

Level 4

Thanks!  That's exactly what I've been doing, I thought there might be an easier way but I guess not.  It's arduous with 1,600 separate resolveNode calls in the form.  I guess I'll just find all the null instances and comment them all out.  I wish the JavaScript interpreter just went to the next line instead of stopping, but I don't think I have any control over that.  

Avatar

Correct answer by
Level 10

You can use the resolveNodes() method, to create a filtered list of suitable nodes by searching for classNames and other properties. So you'll avoid the null-problem completely. 

 

// Filter all field nodes that are not buttons.
var fieldsArray = xfa.form.form1.resolveNodes('#field.[ui.oneOfChild.className ne "button"]');
for (i = 0; i < fieldsArray.length; i++) {
    // add your to be executed …     
    fieldsArray.item(i).presence = "hidden";
} 

 

 

 

// Filter all field nodes.
var fieldsArray = xfa.form.form1.resolveNodes('#field[*]');
for (i = 0; i < fieldsArray.length; i++) {
    // add your to be executed …     
    fieldsArray.item(i).presence = "hidden";
} 

 

 

// Filter all field with a particular name part.
var fieldsArray = xfa.form.form1.resolveNodes('#field.[At($.name, "field") gt 0]');
for (i = 0; i < fieldsArray.length; i++) {
    // add your to be executed …     
    fieldsArray.item(i).presence = "hidden";
} 

Avatar

Administrator

@CR17506599 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni