Webmethods: we can remove an element from documentList while it scrolls

In WEBMETHODS, can an element be discarded from a DocumentList while looping in a DocumentList? If so, how? If not, how can we set the value of the DocumentList variable to null.

thanks
nohsib

+4
source share
3 answers

Tundra includes a service to remove an item from a list of documents ( com.wm.data.IData[] ): tundra.list.document:drop($list[], $index) .

  • $list is a list of documents ( com.wm.data.IData[] ) that you want to remove from
  • $index is the index of the array with a zero value for the item to be deleted

The corresponding Java code is as follows:

 public static final void drop(IData pipeline) throws ServiceException { IDataCursor cursor = pipeline.getCursor(); try { Object[] list = IDataUtil.getObjectArray(cursor, "$list"); String index = IDataUtil.getString(cursor, "$index"); if (index != null) IDataUtil.put(cursor, "$list", drop(list, index)); } finally { cursor.destroy(); } } // returns a new array which contains all the elements from the given arrays public static <T> T[] concatenate(T[] array, T[] items) { if (array == null) return items; if (items == null) return array; java.util.List<T> list = new java.util.ArrayList<T>(array.length + items.length); java.util.Collections.addAll(list, array); java.util.Collections.addAll(list, items); return list.toArray(java.util.Arrays.copyOf(array, 0)); } // removes the element at the given index from the given list public static <T> T[] drop(T[] array, String index) { return drop(array, Integer.parseInt(index)); } // removes the element at the given index from the given list public static <T> T[] drop(T[] array, int index) { if (array != null) { // support reverse/tail indexing if (index < 0) index += array.length; if (index < 0 || array.length <= index) throw new ArrayIndexOutOfBoundsException(index); T[] head = slice(array, 0, index); T[] tail = slice(array, index + 1, array.length - index); array = concatenate(head, tail); } return array; } // returns a new array which is a subset of elements from the given array public static <T> T[] slice(T[] array, int index, int length) { if (array == null || array.length == 0) return array; // support reverse/tail length if (length < 0) length = array.length + length; // support reverse/tail indexing if (index < 0) index += array.length; // don't slice past the end of the array if ((length += index) > array.length) length = array.length; return java.util.Arrays.copyOfRange(array, index, length); } 

However, I agree with MrJames : the best and easiest approach is to create a new list of documents and add only the elements you want to add to the new list using pub.list:appendToDocumentList (or tundra.list.document:append if you use Tundra ) inside the loop step.

+3
source

To do this, you can use a document that deletes a document embedded in the service.

Here is a very simple example, I hope that this will affect the use of the function.

  • Scroll through these docs
  • Branch for collecting indexes of unwanted documents in a loop at the matching stage
  • Outside the loop, use the pub.document: deleteDocuments file to remove the list of documents from the original document.

Hope this helps.

+2
source

I have some tests and it is possible to set the value for a specific Document element to null (using service pub.list: setListItem), but the list of documents will remain the same size.

Another way: iterate over the list of documents and add to the new list of documents those that interest you (pub.list: appendToDocumentList).

Another question on how to set a variable to null can be used Drop in the pipeline

PS: using webMethods 7.1.2

+1
source

Source: https://habr.com/ru/post/1402740/


All Articles