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 with PublicAPI
Context variables:
context.Document - variable of the Document type (Single, Link)
context.User - variable of the User type (Link)
context.Date - variable of the Date type (stores the due date), optional parameter
Namespace:
using EleWise.ELMA.API;
Script text:
PublicAPI.Docflow.Tasks.SendToAcquaintance(context.Document, context.User, context.Date); //Document, Users, Due date (optional parameter)
Script without PublicAPI
Context variables:
AcquaintanceUserList - User type (list 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.
Document - Document type (can be of any document type), defines the document that will be sent.
Namespaces:
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 initiator = (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 = initiator; // - 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(initiator, () => AcquaintanceTaskGroupManager.Instance.AddExecuters(Acq_group, users)); // - add users to the acquaintance list