ELMA API – a tool for developing scripts in ELMA


ELMA API is a set of system methods compiled in an understandable hierarchical structure. ELMA API is intended for developing scripts. You can learn more about developing scripts in this article.

There is a Help for ELMA API with different examples.

ELMA API structure

To work with ELMA API, you need to add the EleWise.ELMA.API namespace.

To start using it, type PublicAPI in the script module of ELMA Designer.

You will see the following:


PublicAPI is the root class for accessing API tree. With IntelliSense, you can see all the nested tree items and find the ones you need.

All API items are divided into units according to ELMA modules:

  • CRM;
  • Document management;
  • Enums (enumerations);
  • KPI;
  • Objects;
  • Portal (includes objects from Messages, Tasks, and Calendar modules);
  • Business processes;
  • Projects;
  • Services

Examples of using ELMA API

The main purpose of ELMA API is to make it easier to create scripts in ELMA by reducing the amount of code required to solve routine tasks.

Below are examples of creating a document and sending it for acquaintance using scripts in ELMA.

Without using PublicAPI methods:

//Create a new contract
            context.Contract = InterfaceActivator.Create<ContractOutgoing>();
            //Choose folder
            context.Contract.Folder = (Folder)FolderManager.Instance.LoadOrNull(13L);
            //Attach the contract's version (file)
            var version = InterfaceActivator.Create<DocumentVersion>();
            version.Document = context.Contract;
            //Set the version status = Current
            version.Status = DocumentVersionStatus.Current;
            // Attach the file of version
            version.File = context.ContractFile;
            //Specify document's name
            context.Contract.Name = "Outgoing contract of " + DateTime.Now.ToShortDateString();
            //Save the new contract

            //Send the contract for approval

            // Get the current user
            var iniciator = (User)EleWise.ELMA.Security.Services.AuthenticationService.GetCurrentUser<EleWise.ELMA.Security.Models.IUser>();
            //Create new group of acquaintance tasks
            var Acq_group = new AcquaintanceTaskGroup();
            //Specify author of the acquaintance task
            Acq_group.CreationAuthor = iniciator;
            //Specify the task's creation date
            Acq_group.CreationDate = DateTime.Now;
            //Set the task's name
            Acq_group.Subject = "Acquaintance with " + context.Contract.Name.ToString();
            //Set the acquaintance task's deadline
            Acq_group.ExecutionDate = Acq_group.ExecutionDate.AddDays(1);
            //Set the task's status = Pending acquaintance
            Acq_group.Status = AcquaintanceStatus.None;
            // Create new acquaintance sheet
            Acq_group.AcquaintanceList = new AcquaintanceList();
            //Add documents and their versions for acquaintance
            Acq_group.Items.Add(new DocumentTaskItem
                Document = context.Contract.CastAsRealType(),
                Version = context.Contract.CurrentVersion != null ? context.Contract.CurrentVersion.CastAsRealType() : null
            var securityService = Locator.GetServiceNotNull<SecurityService>();
            // Select users, who needs to get acquainted with the documents
            //The mechanism below allows you to check if a task's executor is substituted by another employee. If he is, then the task will be assigned to his substitute
            //If you do not need to take substitutions into account, the code below can be simplified
            var users = new List<Pair<EleWise.ELMA.Security.Models.IUser, EleWise.ELMA.Security.Models.IUser>>();
            //Choose the group of users, who needs to get acquainted with the documents
            var usersForAcquaintance = UserGroupManager.Instance.LoadOrNull(2L).Users;
            usersForAcquaintance.ToList().ForEach(user =>
                var addUser = user.ReplacementMode == ReplacementMode.AutoReplacement && user.ReplacementUser != null ?
                              new Pair<EleWise.ELMA.Security.Models.IUser, EleWise.ELMA.Security.Models.IUser>(user.ReplacementUser, user) :
                              new Pair<EleWise.ELMA.Security.Models.IUser, EleWise.ELMA.Security.Models.IUser>(user, null);
                if (!users.Contains(addUser))
            //Add users to the acquaintance's sheet
            securityService.RunByUser(iniciator, () => AcquaintanceTaskGroupManager.Instance.AddExecuters(Acq_group, users));

            //Provide the users with access permissions to the documents
            context.Contract.Permissions.Add(new InstanceOf<DmsObjectPermission>
                New =
                    DmsObject = context.Contract,
                    //Permissions to edit the document
                    PermissionId = EleWise.ELMA.Documents.PermissionProvider.DocumentEditPermission.Id,
                    TypeRoleId = CommonRoleTypes.Group.Id,
                    Assigned = UserGroupManager.Instance.LoadOrNull(2L)
            //Save the document

With PublicAPI:

//Create new contract
            context.Contract = PublicAPI.Docflow.Types.ContractOutgoing.Create(context.ContractFile, PublicAPI.Docflow.Folder.LoadOrNull(13L), "Outgoing contract of " + DateTime.Now.ToShortDateString());
            //Select users, who needs to get acquainted with the document
			var usersForAcquaintance = PublicAPI.Portal.Security.UserGroup.LoadOrNull(2L).Users.Cast<User>();
            //Send the document for acquaintance
			PublicAPI.Docflow.Tasks.SendToAcquaintance((Document)context.Contract, usersForAcquaintance, DateTime.Now.AddDays(1));
            //Provide the users with access permissions to the document
            PublicAPI.Docflow.Document.AddEditPermission((Document)context.Contract, PublicAPI.Portal.Security.UserGroup.LoadOrNull(2L));

 See also:

Frequently asked questions about PublicAPI