Get x number of objects from a list - Mendix Forum

Get x number of objects from a list

8

Currently there is the possibility to get the first record of a list via the list operation – head   and it is possible to get all records except the header (list operation – trail).

When working with batches it would be very helpful to have the option to get a subset from a list for example with offset and amount of objects to get from the list. With this solution you don’t have to do a retrieve from the database for each batch. Furthermore when working from a list you will be sure that all records will be handled.

asked
4 answers

Thanks Jeroen on this update, I had already used that one but forgot that this idea was still open

Created

(fancy late update for the current readers: CommunityCommons.ListTop does this)

Created

Thanks Pavan, I’m trying to avoid any java and see this as a standard functionality that should be available in the list functions.

Created

I voted for the idea, but I guess you can still achieve this easily with custom Java Action :)

something like 

and supporting java method 

	public java.util.List<IMendixObject> executeAction() throws Exception {
		// BEGIN USER CODE
		java.util.List<IMendixObject> ListToReturn = new ArrayList<IMendixObject>();

		if (null == ObjectList) {
			throw new com.mendix.systemwideinterfaces.MendixRuntimeException("List is Null.");
		}

		if (Offset < 0 || Offset >= ObjectList.size()) {
			throw new com.mendix.systemwideinterfaces.MendixRuntimeException("Offset not in range.");
		}

		if (Limit < 0) {
			throw new com.mendix.systemwideinterfaces.MendixRuntimeException("Limit can not be negative.");
		}

		for (int i = Offset.intValue(), j = 0; j < Limit.intValue(); j++) {
			try {
				ListToReturn.add(ObjectList.get(i++));
			} catch (IndexOutOfBoundsException e) {
				break;
			}
		}

		return ListToReturn;
		// END USER CODE
	}

Hope this helps you till Mendix adds this feature

Created