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.
SOLVED

A question on script objects

Avatar

Former Community Member

I have placed a script object on my form to control the field color and it works fine in Adobe Reader X but not in previous versions of Reader and not in Acrobat pro 9.

Can anyone tell me what’s wrong?

The script object looks like this:

form1.#variables[0].RGA_format - (JavaScript, client)

function RGA_colorOld()

xfa.resolveNode("this.ui.#textEdit.border.fill.color").value = "220,220,220";

function RGA_color()

xfa.resolveNode("this.ui.#textEdit.border.fill.color").value = "255,255,255";

And is called from the fields on the docReady event and the Change event by this script:

form1.blanketB.Moder.EftNvnMor::docReady - (JavaScript, client)

RGA_format.RGA_colorOld(this);

form1.blanketB.Moder.EftNvnMor::change - (JavaScript, client)

RGA_format.RGA_color(this);

Regards,

Kirstine

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Kirstine,

When calling the function, you are passing through the object as a parameter. However the function in the script object does not have a corresponding parameter to receive this.

You can probably pass the object reference through as:

RGA_format.RGA_color(this);

However I prefer to declare a variable first and pass this through:

var fieldObj = this.somExpression; // declare a variable to be passed into the function

colourControls.fieldGetsFocus(fieldObj); // calls the function "fieldGetsFocus" in the script object "colourControls"

Notice in the example, I when declaring the function, I have a parameter "fieldObj", to receive the information that is being passed through.

function fieldGetsFocus(fieldObj) // first function

{

     ...

}

A small point about the function in the script object. I know the function is a single line, but I would prefer to see this wrapped in curly brackets.

Lastly changing the fill requires access to the ui properties. These are different for each object type. For example the script you have is for a textfield. This would not work on a numericfield.

I do have an example here of a function that does what you are looking for: https://acrobat.com/#d=XGj9UEk4lSbDSoArnQU8dQ. Note how I check what the object is and then resolve the correct ui property. This makes the function must more reusable.

Hope that helps,

Niall

Assure Dynamics

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi Kirstine,

When calling the function, you are passing through the object as a parameter. However the function in the script object does not have a corresponding parameter to receive this.

You can probably pass the object reference through as:

RGA_format.RGA_color(this);

However I prefer to declare a variable first and pass this through:

var fieldObj = this.somExpression; // declare a variable to be passed into the function

colourControls.fieldGetsFocus(fieldObj); // calls the function "fieldGetsFocus" in the script object "colourControls"

Notice in the example, I when declaring the function, I have a parameter "fieldObj", to receive the information that is being passed through.

function fieldGetsFocus(fieldObj) // first function

{

     ...

}

A small point about the function in the script object. I know the function is a single line, but I would prefer to see this wrapped in curly brackets.

Lastly changing the fill requires access to the ui properties. These are different for each object type. For example the script you have is for a textfield. This would not work on a numericfield.

I do have an example here of a function that does what you are looking for: https://acrobat.com/#d=XGj9UEk4lSbDSoArnQU8dQ. Note how I check what the object is and then resolve the correct ui property. This makes the function must more reusable.

Hope that helps,

Niall

Assure Dynamics

Avatar

Former Community Member

Hi Niall

Thanks, it was a great help.

It took me a little time to figure out to add the variables in the Form Properties Menu. Once I had that part too it worked fine.

Beside I was aware that the ui properties are different for each object type. I solved that by making a function for each object type in my form but this is better.

Once again, thanks a lot. I will probably be back again another day.

J Kirstine

Avatar

Level 10

No problem Kristine, I'm glad it helped.

Just one thing, creating a variable via File > Form Properties > Variables, creates a Global variable. This is useful where you need to value that is accessed by different objects.

The script I have uses a Script/Local variable which is only used within the script. For example,

var i = "hello world";

Declares the variable i and assigns a value.

From that point on within the script you can access (and set) i.

this.rawValue = i;

Hope that helps,

Niall