Sending a document for acquaintance using a script

This article provides an example of a script for sending a document for acquaintance to several users.

Script without using PublicAPI

Context variables:

AcquaintanceUserList - User type (many-to-many link type), defines the users who will receive the document for acquaintance.
Document - Document type (can be of any document type), defines the document that will be sent.


using EleWise.ELMA.Documents.Managers;
using EleWise.ELMA.Documents.Models.Tasks;
using EleWise.ELMA.Security;
using EleWise.ELMA.Security.Models;
using EleWise.ELMA.Services;
using EleWise.ELMA.Tasks.Models;
using EleWise.ELMA.Extensions;
 Script text:
var iniciator = (User)EleWise.ELMA.Security.Services.AuthenticationService.GetCurrentUser<EleWise.ELMA.Security.Models.IUser>(); // - an authenticated user sends the document for acquaintance
var Acq_group = new AcquaintanceTaskGroup(); // - create a new acquaintance task group
Acq_group.CreationAuthor = iniciator; // - identify the user who sent the document for acquaintance
Acq_group.CreationDate = DateTime.Now; // - acquaintance date
Acq_group.Subject = "Acquaintance with the document"+ context.Document.Name.ToString(); // - name of the acquaintance group
Acq_group.ExecutionDate = Acq_group.ExecutionDate.AddDays(1); // - due date of the acquaintance tasks
Acq_group.Status = AcquaintanceStatus.None; // - set the Pending acquaintance status
Acq_group.AcquaintanceList = new AcquaintanceList(); // - create a new acquaintance sheet
Acq_group.Items.Add(new DocumentTaskItem{ Document = context.Document.CastAsRealType(), Version = context.Document.CurrentVersion != null ? context.Document.CurrentVersion.CastAsRealType() : null }); // - select a document and its version for acquaintance
var securityService = Locator.GetServiceNotNull<SecurityService>();
//next, users are loaded to the acquaintance list, taking into account possible substitutions
//if taking into account subsitutions is not required, you can simplify the mechanism
var users = new List<Pair<EleWise.ELMA.Security.Models.IUser, EleWise.ELMA.Security.Models.IUser>>();
context.AcquaintanceUserList.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)) users.Add(addUser); });
securityService.RunByUser(iniciator, () =>   AcquaintanceTaskGroupManager.Instance.AddExecuters(Acq_group, users)); // - add users to the acquaintance list
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here


Context variables:

context.Document - variable of the Document type (Single, Many-to-many)
context.User - variable of the User type (Many-to-many)
context.Data - variable of the Date type (stores the due date), optional parameter


using EleWise.ELMA.API;

Text script:

PublicAPI.Docflow.Tasks.SendToAcquaintance(context.Document, context.User, context.Data);   //Document, Users, Due date (optional parameter)