Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

delete duplicates value in dropdownlist

Avatar

Level 2

Dear all,

I have a table with 2 columns, in each column I have a dropdownlist.

These dropdownlist are binded with SAP table : T001L (couple plant / storage location)

The content is :

Plant       -     Storage Location

PL01               ST01

PL01               ST02

PL01               ST03

PL02               ST04

PL02               ST05

The first dropdownlist is the plant and the second is the storage location

I have 2 requests :

1/ How to delete the duplicates in the first dropdownlist

2/ How to link the 2 dropdownlists : when I choose PL01 in the first DDL, I would like only the attached storage location in the second DDL

Thanks for your help, it is urgent for me.

Kind regards

Véronique

2 Replies

Avatar

Level 2

Great, I found the solution myself after long search in the forum

-------------------------------

var newList = new Array();

var nItems = plant_site.resolveNode("#items").nodes

var count = nItems.length;

var listCount = 0;

for (var i = 0; i < count; i++) {

if ( i == 0 ) {

var oldinfo = nItems.item(i).value;

newList[listCount] = nItems.item(i).value;

listCount++;

}

else

if (nItems.item(i).value != oldinfo)

{

oldinfo = nItems.item(i).value;

newList[listCount] = nItems.item(i).value;

listCount++;

}

} //end for

plant_site.clearItems();

for (var i = 0; i < listCount; i++) {

plant_site.addItem(newList[i]);

} //end for

-------------------------------

I will search for the second part of my request.

Avatar

Level 6

You look like good in JS....here is an idea I would follow.....

Since data need to be related some where I would start with the query that feeds the data in to the form. I would pull up the data as one column madeup of two parts sapated by some special char like "~" instead of two saparate columns.

Then I would add a Global variable with name "GplantSiteList".

Then I would modify your code like following.........

var nItems = plant_site.resolveNode("#items").nodes;
var count = nItems.length;

var plantSiteList = ""; //var to hold combination list of plant and sites
var singleDataItem = ""; //var to collect row items from table
var oldinfo = ""; //for comparision

for (var i = 0; i < count; i++) {

singleDataItem = nItems.item(i).value;
singleDataItem = singleDataItem.split("~"); //split at special char
  if (oldinfo != singleDataItem(0)) {
   oldinfo = singleDataItem(0); //assign the first part to the plant
   plantSiteList = plantSiteList + "***" +singleDataItem(0)+ "#" +singleDataItem(1); //*** is saparater between the sets of values # is saparater between Site values
  }else {
   plantSiteList = plantSiteList + "#" +singleDataItem(1); //# is saparater between Site values;
  }

} //end for

GplantSiteList.value = plantSiteList; //save this value in a global variable

plant_site.clearItems();
plantSiteList = plantSiteList.split("***");
var loadValue;
for (var i = 1; i < plantSiteList.length; i++) {
loadValue = plantSiteList(i)
loadValue = loadValue.split("#");
plant_site.addItem(loadValue(0));

} //end for

Then to load second dd I would add following code under "change" event of the Plant DD

var selectPlant = xfa.event.change; //capture the plant value that is just selected
var plantSiteList;
plantSiteList = GplantSiteList.value; //retrive the global variable

site_list.clearItems(); //assuming site_list is the name of the DD
plantSiteList = plantSiteList.split("***");
var loadValue;
for (j=1;j<plantSiteList.length;j++) {
loadValue = plantSiteList(j)
loadValue = loadValue.split("#");
if (selectPlant == loadValue(0)) {
  for (k=1;k<loadValue.length;k++) {
   site_list.addItem(loadValue(k)); 
  }
  exit; //exit for once satisfied
}
} //end for

hope that helps...........

Good luck