How to write action codes

BackExample 1:

    First, we will write a basic action code to update the description of the record.

    Whenever an action code is called, the system gives a class called the new document. We can get a new document with all the types of action codes.


    To update the description of the form, use the setDescription() function.

    newDocument.setDescription(‘This is a sample action code test.’);

    When we run the above action code and save it as a Before insert action code on any table, whenever a new record is created for that table, this will be the default description. Almost all the tables in AiM has a description field.

    Before the action code is triggered:


    After the action code is triggered:


    Example 2:


    Append user defined fields values of all the locks of an access point to the description of the access point in Key & Access Control module.

    We need to write a before update and before insert action code on the access point.


    First, find the name of the table.

    We will create a before update action code on ae_kac_access_point table.

    First, we need to access the lock to get the UDF fields.

    To access the lock, we need to do the following.

    Go to the data dictionary and find the Façade to which the table belongs to.

    UDF tables are present in UDFFacade. Go to javadocs and look up the façade.

    Go to the javadocs and find the KeyFacade.

    This will contain all the classes needed to access the data.

    We need to bring the Façade to the program. It is a two-step process. First, we need to do an equivalent of an import statement. Then, use it to call the constructor for this class.

    Importing the java classes:

    We can use the javaImporter() function or importPackage function to import the java classes.

    Here, we are importing using var javaImportPackages = javaImporter();

    Import the façade we need. Get the full name of the class from the javadocs.

    com.maximus.fmax.key, com.maximus.fmax.key.dto are the arguments to javaImporter.

    AeKacAccessPointPK class contains primary keys to the table and the DTO class which represents the whole table.

    Now, we need to write a constructor for this.


    Construct the actual façade constructor. We need 2 things to do it. First, we need a context,

    var context = SystemContext.getInstance();

    We give sys admin rights to write for the action code using SystemContext.

    Import com.maximum.fmax.common.framework.util.impl for using SystemContext

    ApplicationContext gives only the right the user has to the action code.

    Now, pass the context to the keyFacade constructor.

    var KeyFacade = new KeyFacade(context);

    We should never call a constructor without a context argument. Context is the permission we are passing to the façade. The façade will not work without the permissions.

    Similarly, we call the UDFFacade.

    var udfFacade = new UDFFacade(context);

    Now, we can use the different function in the Facades.

    Now, we get the list of locks of an access point.

    var aeKacLockDTO = newDocument.getAeKacLockDTOList().get(0);

    We got the first lock(element) from the list.

    But, we should check if at all there is any locks for the access point first before we get the first lock.

    if(newDocument.getAeKacLockDTOList().size() != 0)

    To get the lock UDF details, use the getAeKacLockUdfDTOList() function.

    Build the string from the lock UDF values,

    var searchableUDFLine = seperator + aeKacLockUdfDTO.getCustom001() + “,” + aeKacLockUdfDTO.getCustom002() + “,”+ aeKacLockUdfDTO.getCustom003() + “,”+ aeKacLockUdfDTO.getCustom004();

    Check if the access point description is not null and append the searchableUDFLine:

    if(newDocument.getDescription() != null){

    newDocument.setDescription(newDocument.getDescription() + searchableUDFLine);}



    Go back to Action Code – Training