Skip to main content
rakeshk21205956
Inspiring
Jul 1, 2020 10:04 AM UTC
Answered

Copy all List Box option to other List box via button at once.

I want to achieve something like this :

Document to have 2 list boxes  one filled with options and other empty and along with 1 button (add.)..

I should be able to select multiple option from 1st list box and then press Add button and it will populate all the options from list box1 to list box2 all at once.

 

Currently i have found a file on internet which does the same. but it add 1 option at a time.... when it select multiple options in the 1st listbox.. the add button doesnot work.

 

Plz guide ..

 

Thanks

This topic is closed to new replies. Start a new post to keep the conversation going.
rakeshk21205956
rakeshk21205956Correct answer
Inspiring
Sep 18, 2020 11:55 AM UTC

Below Script worked for me :

 

 

var tableSource=new Array();
var selection = this.getField("List Box1").currentValueIndices;
var List1 = this.getField("List Box1");
var List2 = this.getField("List Box2")
if (typeof selection!="object") {
	tableSource.push([List1.getItemAt(selection,false),List1.getItemAt(selection,true)]);
} else {
	for (var i=0; i<selection.length; i++) tableSource.push([List1.getItemAt(selection[i],false),List1.getItemAt(selection[i],true)]);
}
var tableCible=new Array();
var listeCible=List2.value;
if (typeof listeCible!="object") {
	tableCible.push([List2.getItemAt(0,false),List2.getItemAt(1,true)]);
} 
tableCible.push([List2.getItemAt(i,false),List2.getItemAt(i,true)]);
}
for (var i=0; i<tableSource.length; i++) {
	var abc = 0;
	for (j=0; j<tableCible.length; j++) {
		if (tableSource[i][0]==tableCible[j][0] && tableSource[i][1]==tableCible[j][1]) {
			abc++;
			break;
		}
		if (abc==0) List2.insertItemAt(tableSource[i][0],tableSource[i][1],-1);
	}
}

 

3 replies

try67
Community Expert
Community Expert
Jul 1, 2020 12:05 PM UTC

You can use this code to do it:

var f1 = this.getField("List Box1");
var f2 = this.getField("List Box2");
var selectedItems = f1.value;
if (typeof selectedItems=="object") {
	for (var i in selectedItems) {
		f2.insertItemAt({cName: selectedItems[i], nIdx: -1});
	}
} else f2.insertItemAt({cName: selectedItems, nIdx: -1});

 

Adjust the field names in the first two lines, as needed.

Translate
rakeshk21205956
Inspiring
Jul 6, 2020 8:43 AM UTC

Thanks this script works but it copies the export value of the first list box.

Translate
rakeshk21205956
rakeshk21205956AuthorCorrect answer
Inspiring
Sep 18, 2020 11:55 AM UTC

Below Script worked for me :

 

 

var tableSource=new Array();
var selection = this.getField("List Box1").currentValueIndices;
var List1 = this.getField("List Box1");
var List2 = this.getField("List Box2")
if (typeof selection!="object") {
	tableSource.push([List1.getItemAt(selection,false),List1.getItemAt(selection,true)]);
} else {
	for (var i=0; i<selection.length; i++) tableSource.push([List1.getItemAt(selection[i],false),List1.getItemAt(selection[i],true)]);
}
var tableCible=new Array();
var listeCible=List2.value;
if (typeof listeCible!="object") {
	tableCible.push([List2.getItemAt(0,false),List2.getItemAt(1,true)]);
} 
tableCible.push([List2.getItemAt(i,false),List2.getItemAt(i,true)]);
}
for (var i=0; i<tableSource.length; i++) {
	var abc = 0;
	for (j=0; j<tableCible.length; j++) {
		if (tableSource[i][0]==tableCible[j][0] && tableSource[i][1]==tableCible[j][1]) {
			abc++;
			break;
		}
		if (abc==0) List2.insertItemAt(tableSource[i][0],tableSource[i][1],-1);
	}
}

 

Translate