Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Instance Manager Insert

mr_codycole
Level 2
Level 2

I’ve created a dynamic form with an expanding table and I am having trouble getting instanceManager to do what I want.

I have 2 buttons, one button is in the header and adds rows to the bottom of the table when pressed using:  Table3.Row2.instanceManager.addInstance(1);

It works.

Within each populated row, there is a delete button.

The delete button works using:  Table3.Row2.instanceManager.removeInstance(1)

Is there a way to add an UP and DOWN button to each row, so when clicked the selected row moves either up or down the populated table?

Thank you

1 Accepted Solution
Magus069
Correct answer by
Level 10
Level 10

I gave you a pseudocode to base yourself on it... the code i gave you is not good, it's just an exemple...

The idea of what you want to do is take all values in the selected row and shove it up or down one row...

so in the "up" button you should have something like this

     As you can see, I'm taking the selected index of the row and the row just above by substracting 1 to the actual index

     to do so with the "down" button you would have to add one to the index to get the next row

Don't forget to check if the row above or below exists by checking the index

View solution in original post

10 Replies
Magus069
Level 10
Level 10

//store each values in a var or in an array

var tabValue = new Array(this.resolveNode("cell1").rawValue, this.resolveNode("cell2").rawValue);

//store values of the previous or next row

var tabValues = new Array(this.resolveNode("Row2[" + (this.parent.parent.index +- 1).toString() + "].cell1").rawValue, this.resolveNode("Row2[" + (this.parent.parent.index +- 1).toString() + "].cell2").rawValue);

and then you can give the values to the appropriate field

mr_codycole
Level 2
Level 2

Thank you Robert, do I apply the script to the button?

mr_codycole
Level 2
Level 2

Robert, I've dropped the script into the up and down button as a click event (JavaScript) but I am still unable to shift rows up or down. I am probably missing something.

I shared the file here: https://files.acrobat.com/preview/b4f6e4ad-0fb3-421a-b45b-316c42202cef


Magus069
Correct answer by
Level 10
Level 10

I gave you a pseudocode to base yourself on it... the code i gave you is not good, it's just an exemple...

The idea of what you want to do is take all values in the selected row and shove it up or down one row...

so in the "up" button you should have something like this

     As you can see, I'm taking the selected index of the row and the row just above by substracting 1 to the actual index

     to do so with the "down" button you would have to add one to the index to get the next row

Don't forget to check if the row above or below exists by checking the index

View solution in original post

mr_codycole
Level 2
Level 2

BOOM!

Sorry I misunderstood, it works perfectly!

thank you again!

mr_codycole
Level 2
Level 2

Robert, old post but the remove instance button is removing the wrong instances, for example, if I try to remove instance 4, it will remove instance 2. I have tried adding the button to the up and down script but it causes the script to not work. any idea how I can make this work?

Thank you

Magus069
Level 10
Level 10

I can help you sure, can you show me the code you are using to remove an instance?

mr_codycole
Level 2
Level 2

I got it shortly after posting! my code was

Table3.Row2.instanceManager.removeInstance(1)

I changed it to

Table3.Row2.instanceManager.removeInstance(this.parent.parent.index)

and it works perfectly! Thank you for the quick response