Expand my Community achievements bar.

SOLVED

Getting value of a variable in another script object

Avatar

Level 8
Level 8

Hi all,

I have a scenario where I have one script object (MyTexts1) containing a lot of text for the form (each of the texts are stored in variables (fx. MyTexts1.infoText1). The variables are named after the fields (meaning that I have a field called "infoText1").

So for each field I call a function that takes the name of the field. This function (located in my script object called "functions") should somehow then find the value of the variable in "MyTexts.infoText1".

Now my question is:

How can I achieve the above scenario - and if not why?

Thanks in advance

Cheers

Kim Christensen

Dafolo A/S

Denmark

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

you can do this with just one script object.

For example the "MyTexts" script object with the string variables and a function to return the values.

var infotext1 = "Lorem ipsum dolor sit amet"

var infotext2 = "Non eram nescius Brute cum"

function getText(FieldNumber) {

          return eval("infotext" + FieldNumber);

}

To populate a field you can call the function in the script object with an argument, which is the alias for the varaible number you want to return.

You don't need to enter the full somExpression to your script object, the name is enough.

Textfeld1.rawValue = MyTexts.getText(1);

View solution in original post

4 Replies

Avatar

Level 10

Hi,

I can't follow you description.

You have a script object "functions" right?!

In this script object you have declared variables, but how?

Avatar

Level 8
Level 8

HI again radzmar,

You are right - I could have been more precise in my description :-)

i have two script objects.

In the first one ("MyTexts") I have a lot of texts declared like this:

var infotext1 = "blah blah blah";

var infotext2 = "blah blah blah blah";

In my second script object ("functions"), I have a function that looks something like this:

getTexts(fieldName)

{

     var textValue = xfa.form.variables.MyTexts.(value of fieldName);//pseudocode as I don't know the syntax to reach this value

     return textValue

}

Can you help me understand what I should do to achieve this - or maybe you have a better proposal for reaching my goal?

Thanks in advance

\Kim

Avatar

Correct answer by
Level 10

Hi,

you can do this with just one script object.

For example the "MyTexts" script object with the string variables and a function to return the values.

var infotext1 = "Lorem ipsum dolor sit amet"

var infotext2 = "Non eram nescius Brute cum"

function getText(FieldNumber) {

          return eval("infotext" + FieldNumber);

}

To populate a field you can call the function in the script object with an argument, which is the alias for the varaible number you want to return.

You don't need to enter the full somExpression to your script object, the name is enough.

Textfeld1.rawValue = MyTexts.getText(1);

Avatar

Level 8
Level 8

Hi again radzmar,

Thanks alot

This made it easy for me - even though I need more than one scriptobject (I have to handle multiple languages). But it works perfectly :-)

Once again thank you for your help - it is most appreciated

Cheers

\Kim