Question & Answer
Question
How to remove a selected element from a list in BPM?
Answer
On Demand Consulting
Author: Mikhail Zilbergleyt
First, we need to determine which elements from TWList were selected.
Based on the Java Script API reference article in the Knowledge Center:
Because the internal JavaScript implementation is different for Client Side Human Services and Server Side I will address them separately.
Server Side Processing ( e.g Heritage Human Service )
Although the KC states that
In my examples the tw.local.mylist variable is declared as List of Strings.
One possible implementation iterates backwards over sorted
On the Client Side Human Service the
The
Native java script array has no method to remove an array element. Thus we need to copy all not selected elements into new array:
var purged = []
var selected = tw.local.mylist.listAllSelectedIndices;
for ( var i=0; i<tw.local.mylist.length; i++ )
{
if ( selected.indexOf(i) == -1)
purged[purged.length] = tw.local.mylist[i];
}
tw.local.mylist = purged;
Author: Mikhail Zilbergleyt
First, we need to determine which elements from TWList were selected.
Based on the Java Script API reference article in the Knowledge Center:
int[] listAllSelectedIndices
Returns an array of all of the selected indices of this array. The indices are returned ordered so that the most recently selected index is in position 0 and the least recently selected at the end.Because the internal JavaScript implementation is different for Client Side Human Services and Server Side I will address them separately.
Server Side Processing ( e.g Heritage Human Service )
Although the KC states that
listAllSelectedIndices
is an int[] on the server side it is not the same as the native JavaScript Array.listAllSelectedIndices is dynamically generated from the listSelected
TWList which stores all selected list elements.In my examples the tw.local.mylist variable is declared as List of Strings.
One possible implementation iterates backwards over sorted
listAllSelectedIndices and removes elements from
tw.local.mylist:var sortNumber = function(ab) { return a - b; } // .toArray(). returns native array which has the sort function // sortNumber compares elements as integers since default sort compares them as strings var sorted = tw.local.mylist.listAllSelectedIndices.toArray().sort(sortNumber) for( var i= sorted.length-1 ; i >=0; i-- ) { tw.local.mylist.removeIndex(sorted[i]); } ? |
On the Client Side Human Service the
listAllSelectedIndices
and tw.local.mylist are a native Java Script array.The
listSelected
is not available on the CSHS.Native java script array has no method to remove an array element. Thus we need to copy all not selected elements into new array:
var purged = []
var selected = tw.local.mylist.listAllSelectedIndices;
for ( var i=0; i<tw.local.mylist.length; i++ )
{
if ( selected.indexOf(i) == -1)
purged[purged.length] = tw.local.mylist[i];
}
tw.local.mylist = purged;
[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSQTW3","label":"IBM On Demand Consulting for Hybrid Cloud"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"","label":""}}]
Was this topic helpful?
Document Information
More support for:
IBM On Demand Consulting for Hybrid Cloud
Software version:
All Versions
Document number:
776277
Modified date:
17 March 2019
UID
ibm10776277
Manage My Notification Subscriptions