Community Commons Module

Dear community, As a result of browsing through your questions on this forum and investigating several projects, we just published a module with a lot of reusable Java actions. The module can be found in the AppStore. The module addes functionality for working with Dates, Batches, Strings, Internet, Files, Configuration etc. See the documentation or screenshot for a complete list of functions. Feel free to post any bugs concerning the module, or suggestions for function to be added (with or without code) in this thread. The functions can be invoked from Microflows, or from Java using communitycommons.<folder>.<function>(arguments) A list of the functions available in 1.0: Batches AddToBatch - Add an object to a batch. CommitBatch - Commit a batch DeleteAll - Removes ALL instances of a certain domain object type using batches. DateTime DateTimeToLong - Converts a DateTime to a Unix timestamps. (Milliseconds since 1-1-1970) LongToDateTime - Converts a Unix timestamp to a dateTime object YearsBetween - Calculates the number of years between two dates. Logging Log - Prints a message to the Mendix log. SimpleLog - Logs a message to 'Community Commons' with loglevel 'Info'. TimeMeasureStart - Start timing something, and print the result to the log. TimeMeasureEnd - End timing something, and print the result to the log. Misc CreateUserIfNotExists - (Microflow) Create a user with predefined password an role. Useful during startup for integration purposes. DuplicateFileDocument - Clones the contents of one file document into another. GetApplicationUrl - Returns the runtime URL of this application. GetFileSize - Returns the filesize of a file document in bytes. GetRuntimeVersion - Returns the runtime version of this application. RetrieveURL - Retrieves data (such as an HTML page) from an URL using the HTTP protocol, and returns it as string. StoreURLToFileDocument - Retrieve a document from an URL using a HTTP GET request. ThrowException - This action always throws an exception (of type communityutils.UserThrownError), which is, in combination with custom error handling, quite useful to end a microflow prematurely or to bail out to the calling action/ microflow. ORM CommitWithoutEvents - Commits an object, but without events. Clone - Clones objects DeepClone - Clones objects, their associations and even referred objects. GetGUID - returns the Global Unique Identifier (GUID, or id) of an object. GetOriginalValueAsString - Returns the original value of an object member, that is, the last committed value. GetTypeAsString - Returns the actual type of an Entity. Useful as alternative way to split upon inheritance, or as input of other functions in this module. MemberHasChanged - Checks whether a member has changed since the last commit. Useful in combination with getOriginalValueAsString. RefreshClass - Refreshes a certain domain object type in the client. Useful to enforce a datagrid to refresh for example. StringUtils Hash - Hashes a value using the SHA-256 hash algorithm. HTMLEncode - Encodes a string to HTML Entities, so that they can be displayed in the browser without breaking any layout. RandomString - Generates a random alphanumeric string of the desired length. RegexReplaceAll - Performs a regular expression. Identical to the microflow expression funciton 'replaceAll'. RegexTest - Returns true if a value matches a regular expression. StringLeftPad - Pads a string on the left to a certain length. StringLength - Returns -1 if the value is empty, the length otherwise. StringRightPad - Pads a string on the right to a certain length. StringTrim - Left and right trims a string (that is; removes all surrounding whitespace characters such as tabs, spaces and returns). SubstituteTemplate - Given an object and a template, substitutes all fields in the template. Supports attributes, references, referencesets and project constants.
9 answers

Is there a way that we, the community, can add examples or documentation to these functions to help others, rather than asking you to document?

For example, I just used the refreshClass functionality. I assumed from the name (and how some other widgets work) that I should use the Class attribute of a datagrid to give it a unique identifier, then pass that string as the parameter. Not correct. What you really need to pass is the entity module and name, like 'KB.Symptom'.


See this thread:

* Update: added locking functionality to community commons 1.1 *

The following functions can be used to manage locks. Not that this locking functionality does not prevent edits on the database level, so acquireLock(item) should be used in any Microflow manipulating the object!

Good practice might be to acquire the lock in any before commit, and abort the commit if the lock was not obtained.

  • acquireLock(item) - Tries to acquire a lock. Returns true if granted, or if already locked by this session.
  • releaseLock(item, force) - Releases a lock
  • waitForLock(item, timeout) - Identical to acquirelock, but on failure, waits until the lock can be obtained.
  • getLockOwner() - Returns the of the lock owner, or empty if the item is not locked.

A new version of community commons has just been released. Please submit any problems here or at

If you created some easily reusable utlity methods or regular expressions, feel free to share them here, and we will try to publish it in the next release of the module.


We have seen the IsInDevelopment is added to the community commons, because the function getDTAPMode is deprecated.

Now we still need a function that is capable to identify the environment (acceptance or production) and not only if the model is opened by the modeller.

Any thoughts?


How would I use RegexReplaceAll to replace all non numeric characters?


Cloning a Object with an auto number attribute fails.

Should get meta data of the attribute and check if it is an AutoNumber


  public static Boolean cloneObject(IContext c, IMendixObject source,
            IMendixObject target, Boolean withAssociations)
        Map<String, ? extends IMendixObjectMember<?>> members = source.getMembers(c);

        for(String key : members.keySet()) { 
            IMendixObjectMember<?> m = members.get(key);
            IMetaPrimitive meta =  source.getMetaObject().getMetaPrimitive(m.getName());
            if (m.isVirtual() || (meta != null &&  meta.getType() == PrimitiveType.AutoNumber))
            if (withAssociations || ((!(m instanceof MendixObjectReference) && !(m instanceof MendixObjectReferenceSet))))
                target.setValue(c, key, m.getValue(c));
        return true;

As the GitHub page for CommunityCommons point here I guess this is still the place to report this issue:

deepClone ignores changedDate and createdDate, but clone copies these as well.

I think the correct behaviour is that both functions should ignore both of these attributes (and this should be documented as such in their description).


See this thread:

Proposal for locking functionality in communitycommons:

Locking support:

  • acquiteLock(anyobject) returns true if granted
  • releaseLock(anyobject)
  • isLockedByOtherUser(anyobject) returns true if somebody else has a lock
  • hasLock(anyobject) returns true if you have the lock

Lock batching:

  • startLockbatch()
  • addToLockBatch(anyobject)
  • acquireLockBatch() return true if all objects in the lockbatch could be acquired, false if not. If false, all objects in the batch are released (to prevent deadlocks)

Is it possible to suggest some java actions and if the answer is yes, who do i send the code?