Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

dynamically add text value from instanceManager to another instanceManager

Avatar

Former Community Member

Hi,

I have a dynamic form which have two subforms with instanceManagers. One is called options, and other is description. Subform "options" has a button which adds an instance to both InstanceManagers "_options" and "_description".

I click the button two times so i have three instances of each. Each "_options" instance has a field OPTION, and each "_description" instance has a field DESCRIPTION. I would like to write a code which will automatically set the text value of  OPTION to text value of DESCRIPTION.

example:

- options

     -OPTION (input text field)

- descriptions

     -DESCRIPTION

click

click

- options

     -OPTION(1)(input text field)

     -OPTION(2)(input text field)

     -OPTION(3)(input text field)

- description

     -DESCRIPTION(1)(input text field)

     -DESCRIPTION(2)(input text field)

     -DESCRIPTION(3)(input text field)

filling out the option fields

- options

     -OPTION(1)(rawValue: Soup is good)

     -OPTION(2)(rawValue: Soup really sux)

     -OPTION(3)(rawValue: Soup is ok)

and here's my problem - how do i get these values to the other instanceManager? I have a code which doesn't work but i don't want to suggest you anything. Please, help me out, i'm fighting with this instance reference bs for some time now

1 Accepted Solution

Avatar

Correct answer by
Level 10

You need to use xfa.resolveNode to parse the instance index count.

I just did a quick test with a couple of tables, on the exit event of a field in Table1 I set a corresponding field in Table2 to the same value. Works the same with subforms.

xfa.resolveNode("Table2.Row1[" + this.parent.index + "]").TextField1.rawValue = this.rawValue;

Depending on how many levels deep in the repeating subform your field is you will need to play with the "this.parent.index" to get the path to the repeating subform (this.parent.parent.index, etc.).

Hope that's what you're looking for!

View solution in original post

7 Replies

Avatar

Correct answer by
Level 10

You need to use xfa.resolveNode to parse the instance index count.

I just did a quick test with a couple of tables, on the exit event of a field in Table1 I set a corresponding field in Table2 to the same value. Works the same with subforms.

xfa.resolveNode("Table2.Row1[" + this.parent.index + "]").TextField1.rawValue = this.rawValue;

Depending on how many levels deep in the repeating subform your field is you will need to play with the "this.parent.index" to get the path to the repeating subform (this.parent.parent.index, etc.).

Hope that's what you're looking for!

Avatar

Level 10

Hi,

Your subforms options and description will have an index property that returns the occurance of a particular subform in a list of subforms.  So using that you can put the following JavaScript code in the calculate event of the DESCRIPTION field;

 

"description.index" tells us which occurance we are working with (e.g. 0,1 or 2)

so, options.all.item(description.index) matches that occurance in the options subforms.

and ".OPTION.rawValue" references the value of the OPTION filed.

Hope that helps.

Bruce

options.all.item(description.index).OPTION.rawValue

Avatar

Former Community Member

Thank you Jono for help. I tried to use your script but it seems im doing something wrong. I get an error:

1:XFA:form1[0]:formularz[0]:PrintButton1[0]:click

SyntaxError: invalid assignment left-hand side

Please look at the screenshot attached.assignment.jpg

Further assistance will be great - this is my second form in life, and first one so advanced - i am getting lost with the code

Thanks!

Avatar

Former Community Member

BR001 - thanks, this one works with one instance. What i am trying to do is to assign the value of one field to other with one button but it has to work for every instance with just one click.

example:

Subform1 has 3 instances therefore Subform2 has 3 as well. (button add adds instances to both forms)

I fill in the text fields of

Subform1[0].TextField1,

Subform1[1].TextField1

Subform1[2].TextField1

and want to copy it to

Subform2[0].TextField2

Subform2[1].TextField2

Subform2[2].TextField2

I would like the script to be dynamic so it wouldn't matter how many instances i have, it will always work with just one click for all of them.

Thanks!ass_2.jpg

Avatar

Former Community Member

Jono, i found out what was wrong - it works now but only if i have a button inside my subform. It helps a lot since i did not know how to set instance reference before Any chances you could help me out with a button which will be at the same level as subforms and will assign text in all instances with just one click?

thank you

Avatar

Level 10

With the code that Bruce and I gave you there's no need to use a button. Bruce's went on the Calculate event and mine went on the Exit event (though both would work the other way around too ), then the data updates automatically.

To do it with a button you need to write a loop to run through the different instances.

Avatar

Former Community Member

That's great stuff i didn't consider making it this way and it's much much more user friendly if it fills out every time you change the value cool stuff. Thanks a lot guys!!!