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.
SOLVED

Help on ListBox

Avatar

Level 1

Hi All,

I am quite beginner in adobe live cycle designer. I have a requirement where there are two list boxes (Say L1 and L2).

Multi selection has been enabled for both the List boxes. There is an add button and a remove button.

On clicking Add button, the selected entries should be removed from L1 and to be added to L2.

On clicking Remove button, the selected entries should be removed from L2 and to be added to L1.

I am using javascript as the scripting language and Adobe Live Cycle Designer 7.1.

Can anyone tell me how can I achieve this using javascript.

Thank You.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

You can remove a node form the XML by using the sample code below.

xfa.datasets.data.nodes gives you the access to the root node in the XML.

And from there you need to traverse node by node to get to the node as you want.(Refer to the For loop below Where I am trying to delete userImageURL tag from XML)


//Remove the entire Country List from the Submit XML
var nodeRemove = xfa.datasets.data.nodes.item(0).nodes.item(1);
xfa.datasets.data.nodes.item(0).nodes.remove(nodeRemove);

  
//Remove the userImageURL tag from the Output XML
for(i=0;i<xfa.datasets.data.nodes.item(0).nodes.item(0).nodes.length;i++){
var strTagName = xfa.datasets.data.nodes.item(0).nodes.item(0).nodes.item(i).name;
if(strTagName == "userImageURL"){
  nodeRemove = xfa.datasets.data.nodes.item(0).nodes.item(0).nodes.item(i);
  xfa.datasets.data.nodes.item(0).nodes.item(0).nodes.remove(nodeRemove); 
}
}

Thanks
Srini

View solution in original post

6 Replies

Avatar

Level 1

Hi Srini,

Your reply was extremely helpful. I had captured the logic from your coding and did a small modification, as the list box is multiselection enabled.

Here is my code for adding the selected values from ProhibitedPlants_ListBox to PemittedPlants_ListBox:

if

(ProhibitedPlants_ListBox.selectedIndex> -1)//IF AT LEAST ONE ITEM IS SELECTED

{

//xfa.host.messageBox("AT LEAST ONE ENTRY SELECTED");

var length1 = ProhibitedPlants_ListBox.items.nodes.length;

for(var j=length1-1;j>=0;j--)//ITERATING THROUGH ProhibitedPlants

{

if (ProhibitedPlants_ListBox.getItemState(j)==true )//FILTERING THE SELECTED ITEMS FROM ProhibitedPlants

{

var cEntry = ProhibitedPlants_ListBox.getDisplayItem(j);//GETTING SELECTED ITEM TEXT

//xfa.host.messageBox("cEntry "+cEntry+ "Selected Index: "+j);

var oList = RegulatoryInfo.resolveNode("PemittedPlants_ListBox.#items");//RESOLVING NODE FOR PemittedPlants

// Make sure entry does not already exist

var bFound = false;

for(var i=0;i<oList.nodes.length;i++)//ITERATING THROUGH PemittedPlants. IT CHECKS WHETHER PemittedPlants ALREADY HAVE SELECTED VALUE FROM ProhibitedPlants

{

if(oList.nodes.item(i).value == cEntry)//IF PemittedPlants ALREADY HAS VALUE SELECTED IN ProhibitedPlants

{

bFound

= true;

break;

}

}

if(!bFound)//IF PemittedPlants DOES NOT HAVE VALUE SELECTED IN ProhibitedPlants

{

PemittedPlants_ListBox.addItem(cEntry);

//ADD THE SELECTED ENTRY TO PemittedPlants

ProhibitedPlants_ListBox.deleteItem(j);

//DELETE THE SELECTED FROM rohibitedPlants

}

else

{

//xfa.host.messageBox("Duplicate present IN LISTBOX1");

}

}

}

}

else

{

xfa.host.messageBox("Select factory from Prohibited plants list");

}

This code worked fine for multiple selection also.

But there is one more problem in this. The listboxes are bound to two nodes respectively from dataview. The values in the list box are populated from these nodes.

MaterialMaster(RootNode for adobe form)
--ProhibitedPlants (Source for ProhibitedPlants_ListBox )
  --PlantID (String Attribute)
  --PlantDesc (String Attribute)

--PermittedPlants (Source for PemittedPlants_ListBox )
   --PlantID (String Attribute)
   --PlantDesc (String Attribute)

Problem is: Eventhough the values got added from ProhibitedPlants_ListBox to PemittedPlants_ListBox, the data was not changed from the respective node (ProhibitedPlants and PermittedPlants respectively).

Can you tell me, how can I move the selected entries from node "ProhibitedPlants" to "PermittedPlants".

Thank You

Avatar

Level 10

Eventhough the values got added from ProhibitedPlants_ListBox to PemittedPlants_ListBox, the data was not changed from the respective node (ProhibitedPlants and PermittedPlants respectively).

Srini: What do you mean by the above statement? If I understand correctly you are expecting the data in XML needs to be changed as soon as you move the item from one ListBox to other. The source XML will not change when you move the items between the ListBoxes. But when you generate the XML from the PDF ( by using "xfa.data.saveXML();" command), you should see a difference in the data in the XML.

Hope this helps..

Thanks

Srini

Avatar

Level 1

Hi Srini,

I am using adobe forms in context to an SAP technology named Webdynpro. The data for ListBoxes will be loaded from SAP system, which will come to the form as elements to the nodes- ProhibitedPlants and PermittedPlants (These nodes are present in the data View of adobe livecycle designer).

That is: The nodes in dataview (ProhibitedPlants and PermittedPlants) will be loaded with values from SAP using java code. Because of the mapping of these nodes with the list boxes, the value will be loaded in the list boxes.

Now, using the script, i am able to exchange the values between the list boxes. But it is not exchanging the values in the nodes, because of which I am not getting the changed values in the java coding, where I will write the business transactions.

So, i wanted know, whether any script is there to interchange the values between the nodes, similar to the script used for listboxes.

Is there any code like

xfa.resolveNodes("xfa.record.MaterialMaster.PermittedPlants[*].value");

to access the Node in dataview [i.e. PermittedPlants (which is child of the root node MaterialMaster) ].

Also, it it possible to use some script to delete the values from this node.

Hope you got my query.

Thanks for spending your precious time to resolve my issue

Avatar

Correct answer by
Level 10

Hi,

You can remove a node form the XML by using the sample code below.

xfa.datasets.data.nodes gives you the access to the root node in the XML.

And from there you need to traverse node by node to get to the node as you want.(Refer to the For loop below Where I am trying to delete userImageURL tag from XML)


//Remove the entire Country List from the Submit XML
var nodeRemove = xfa.datasets.data.nodes.item(0).nodes.item(1);
xfa.datasets.data.nodes.item(0).nodes.remove(nodeRemove);

  
//Remove the userImageURL tag from the Output XML
for(i=0;i<xfa.datasets.data.nodes.item(0).nodes.item(0).nodes.length;i++){
var strTagName = xfa.datasets.data.nodes.item(0).nodes.item(0).nodes.item(i).name;
if(strTagName == "userImageURL"){
  nodeRemove = xfa.datasets.data.nodes.item(0).nodes.item(0).nodes.item(i);
  xfa.datasets.data.nodes.item(0).nodes.item(0).nodes.remove(nodeRemove); 
}
}

Thanks
Srini

Avatar

Level 9

Hello Srini,

I am on the same boat. I am using an sample xml data to embed in the form, There are different sections. Lets say there is a section called ItemSection.

Within that section we have ItemNumber,ItemDescription, ItemPrice etc. Basing on the ItemNumber all the associated fields are updated. There are approx 200 items (say.). Suppose the user has choosen the item 23. Is it possible to delete all the items except the item23 so that when the user will submit the data only the item23 value will be submitted as xml instead of all the embdded data ?

Thanks.

Bibhu.