Hi team,
i have a requirement like, a DocumentList which contains more than 1000 records. i have to take only first 50 from that. is there any way filter first 50 records.
i can achieve this by using loop. But i don’t want to go with performance issue.
i have tried with groupDocuments, searchDocuments, etc. didn’t worked out.
can any one suggest me on this.
Hi Ibrahim,
I do not see any way beside using a LOOP step and exit from it when $iteration reaches 50.
One exception might be if you have a criteria matching only the first 50 documents but not the other ones which might allow the usage of pub.xml:queryXMLNode.
Regards,
Holger
One nice way might be to use a ForEach and specify an index filter such as 1-50 to limit to the first 50
Hi Dave,
but this will work only on latest versions of wM if I remember right.
As Ibrahim didnt mention the currently used version I was trying to suggest a solution, which might be possible even on older versions.
@ibshaik786:
Can you provide is your current wM version for verification, please?
Regards,
Holger
ForEach has been around for some years now - I’d have to double check exactly how far back, but it’s a feature many people tend not to use because they’re used to the loop construct, but in this example, it’s a much nicer solution.
Loop has been there forever of course
There’s probably a quick solution in a javaservice as well that would be a small effort
@ibshaik786
You should also try this in a Java Service, to compare performance.
For the java savvy…
Define service contract as:
Then put the following code into the java service.
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
IData[] in = IDataUtil.getIDataArray( pipelineCursor, "in" );
String top = IDataUtil.getString( pipelineCursor, "top" );
pipelineCursor.destroy();
IData[] out;
out = java.util.Arrays.copyOfRange(in, 0, Integer.parseInt(top));
// pipeline
pipelineCursor = pipeline.getCursor();
IDataUtil.put( pipelineCursor, "out", out );
pipelineCursor.destroy();
Run and pass in the number of elements you want from the top…
version: 9.12
ForEach was avail in v9.12 See link below (pg 275)
I’m certain that the Java Version I posted would be significantly more performant over ForEach or Loop though (without testing to confirm )
Hi Dave,
thanks for pointing this out.
Looks like this has been introduced in wM 9.12 as I could not find a hint to this in the 9.10 version of this dokument.
Regards,
Holger
Hi,
the Index field should be specified as ‘0-49’ for the first 50 documents.
When using index as shown in the screenshot you will retrieve the documents from 2 to 51 as array indexing starts with 0 for the first object.
Regards,
Holger
Hi,
in this case you should either put a note somewhere to specify the value of top one lower than intended or subtract 1 from the parsed Integer. Otherwise you will get one document to much.
Regards,
Holger