parseInteger in retrieve action constraint

3
Good day, I've got an entity that has an attribute with a string value. Now I would like to do a retrieve where an Integer value equals the string value. i.e. Retrieve action on SomeEntity [parseInteger(StringAttribute) = $OtherEntity/IntegerAttribute] The reason I am doing this is because the StringAttribute value in SomeEntity can be 00001523694, 00488567, 0145 etc. And this needs to compare to the IntegerAttribute value of OtherEntity which has the values 1523694, 488567, 145. But it is giving me a 'Unknown function parseInteger' error. How would I go about doing this?
asked
4 answers
3

You can do it in Java with some OQL, the following code does what you want, I can send you a test project if you'd like to see it. Or you can just plug it in and add the rest of your xpath to the OQL statement.

The java action needs to return the object you are trying to retrieve.

The code is:

        String OQLQuery =
        "SELECT DISTINCT o/id AS oid" +
        " FROM " + "ModuleName.\"ObjectName\"" + " AS o" +
        " WHERE " + "CAST(o.StringAttributeName AS INTEGER) = " +
        ObjectName.MemberNames.ReferenceName + "/" + OtherObjectName.getType() + "/" + OtherObjectName.MemberNames.IntegerAttributeName;

        IDataTable table = Core.retrieveOQLDataTable(getContext(), OQLQuery );

        IMendixIdentifier objectID = null;

        if( table.getRowCount() > 0) {
            for( IDataRow row : table.getRows() ) {
                Object oid = row.getValue(getContext(), "oid");
                if ( oid instanceof IMendixIdentifier )
                    objectID = (IMendixIdentifier) oid;
                else  {
                    // errormessage
                }
            }
        } else {
            // nothing found
        }

        // add check here to avoid nullpointer (for when objectID is still null) unless you've already handled this
        List<IMendixObject> foundObjects = Core.retrieveXPathQuery(getContext(), "//"+ ObjectName.getType() + "[id = " + objectID.getGuid() + "]");

        if (foundObjects .size() == 1)
            return foundObjects.get(0); // return found object
        else
            return null; // error, nothing found
answered
3

You cannot call the parseInteger in a xPath constraint.

I see 2 ways which you can go about.

You can either introduce an additional attribute to the object. The attribute should be calculated on a after commit so that it mimics the String as an Int.

The other solution would be to first create a variable which essentially does the same thing but is not stored in the database. So create an integer variable give that a initial value of ParseInteger(IntegerAsStringValue) and use that compare it to the other int in your retrieve.

answered
0

Create an integer variable with value: parseInteger(attribute) then use that variable in your retrieve xpath, ie. [integerVariableName = $OtherEntity/Attribute]

answered
0

With using a retrieve from database by xpath, you can't use the parseInteger functionality. I'm afraid that workarounds will take too long especially when you store over a million records in this table.

answered