Adding users to the list of document approvers with a script

Let's say the context.Doc variable of a process stores a document, which already has an active approval sheet and the context.Users variable (User type, Many-to-many link type) stores the list of users to add to the list of the document approvers and assign approval tasks to. You can do it using the following script.

Script without using PublicAPI
For the script to work, add the assemblies:



using EleWise.ELMA.Documents.Managers;
using EleWise.ELMA.Documents.Models.Tasks;
using EleWise.ELMA.Model.Common;
using EleWise.ELMA.Model.Entities;
using EleWise.ELMA.Model.Entities.ProcessContext;
using EleWise.ELMA.Model.Managers;
using EleWise.ELMA.Model.Types.Settings;
using EleWise.ELMA.Security.Models;
using EleWise.ELMA.Tasks.Models;

Script text:

var group = ApprovementTaskGroupManager.Instance.GetGroupsByDocument(context.Doc).LastOrDefault();//get the last approval
ApprovementTaskGroupManager.Instance.AddExecuters(group, context.Users.Select(u => new Pair<IUser, IUser>(u, null)));
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here

Context variables:

context.Document - variable of the Document type
context.User - variable of the User type, Many-to-many link type


using EleWise.ELMA.API;

Script text:

var group = PublicAPI.Docflow.Tasks.GetApprovementGroupsByDocument(context.Document).LastOrDefault();//get the last approval
PublicAPI.Docflow.Tasks.AddExecutors(group, context.User);