In Microflow I use the following Xpath to achieve this:
[id != $metaobjectname]
Maybe this will also work within Java actions.
If you are searching for duplicate keys, i can imagine you can avoid the problem by defining uniqueness constraints in the domain model of your application? This way you do not need an java action at all.
I think this cannot be expressed using XPath, so the only solution i see is retreive all objects, and create a java action which iterates them to check for double items.
this should be something like
List<IMendixObject> objects = Core.retrieveXPathQuery(context, "//"+entityname);
for(IMendixObject object1 in objects ) {
for(IMendixObject object2 in objects) {
if (object1.getMemberValue("key") == object2.getMemberValue("key")) {
//duplicate
} } }
a, depending on the size of your collection, faster approach might be
List<IMendixObject> objects = Core.retrieveXPathQuery(context, "//"+entityname);
for(IMendixObject object1 in objects ) {
List<IMendixObject> objects2 = Core.retrieveXPathQueryEscaped(context, "//%s[%s='%s']", entityname, "key", object1.getMemberValue("key"));
if (objects2.size() > 1) {
//duplicate
} }
p.s. I did not verify the function name, might be an error in there