How to slice a list in a microflow

0
I have a list of filtered items that has gone by some list operation filters. Therefore I can’t use the custom length from a retrieve activity. So, how can I just simply get the first 5 items off that list without looping and do it 5 more times in 5 different microflows with 5 different types of items?   The equivalent of this in Javascript is https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
asked
4 answers
0

If you want to avoid the loop function you can also create a variable (integer) counter and add the first item on the list and then add one to the counter. Go back with a merge activity until you reached 5 and then continue?

 

Otherwise apply the filter in a constraint while retrieving 5 objects. You need some sort of variables to determine where you want to slice the list I suppose

answered
3

Hi Klaustin,
I created a java action a while ago for this purpose, which you can use in microflows.
If you want to use it a nanoflow, you would have to create a similar Javascript Action. 
Please check out the code below.


Java action Slice
General tab

Type parameter tab

java code
 

	@java.lang.Override
	public java.util.List<IMendixObject> executeAction() throws Exception
	{
		// BEGIN USER CODE
		int startValue  = Start != null ? Start.intValue() : 0;
		int endValue = End != null ? End.intValue() : List.size();
		return List.subList(startValue, endValue);
		// END USER CODE
	}

 

answered
1

@op here

if your case is exactly slicing the first 5 items in a list, there is actually a Java Action called ‘List Top’. Horrible naming, but whatever. Otherwise follow @Nils Klatter answers’ (probably on top of this answer)

answered
0

There are no existing methods, so you have to write your own javaaction to implement the logicThere are no existing methods, so you have to write your own javaAction to implement the logic

answered