logo

Writing an approval sheet to a context variable

In ELMA, after starting approval of a document, you can manually generate an approval sheet and download it to your computer. 

If there is a document in a process context, which is pending approval or approved, you can write its approval sheet to a context variable. The document does not have to be approved in the process; it may be approved in Web Application with the standard Approval operation; in the process, it can be selected manually or obtained with a script.

In this script, the final approval sheet (if there were more than one) is written to the context variable, this script can be executed at any process stage if there is a document in the process context.

Script without using PublicAPI

Context variables:

Context.Contract – variable that stores the approved document.
Context.ApprovalSheet – variable of the Attachment type

For the script to work, add the namespaces:

EleWise.ELMA.Documents.Managers
EleWise.ELMA.Common.Models
EleWise.ELMA.Common.Managers
EleWise.ELMA.Runtime.Managers
EleWise.ELMA.Files
EleWise.ELMA.Services

Script text:

var AppGroup = ApprovementTaskGroupManager.Instance.GetGroupsByDocument(context.Contract).LastOrDefault();
if (AppGroup != null)
{
    var idList = new List<long>();
    idList.Add(AppGroup.Id);
    context.ApprovalSheet = (Attachment)AttachmentManager.Instance.Create();
    context.ApprovalSheet.File = InterfaceActivator.Create<BinaryFile>();
    context.ApprovalSheet.File.Name = "Approval sheet.pdf";
    context.ApprovalSheet.File.CreateDate = DateTime.Now;
    //the last argument of the Export method is responsible for converting to .pdf; converted if true
 
    context.ApprovalSheet.File.ContentFilePath = ApprovementListManager.Instance.Export(context.Contract, idList, true);
    Locator.GetServiceNotNull<IFileManager>().SaveFile(context.ApprovalSheet.File);
}

After executing the script, a pdf file with the approval sheet will be written to the context variable.

Creating a similar script with PublicAPI
Documentation on PublicAPI is available here

Context variables:

context.Document - variable of the Document type
context.Attachment - variable of the Attachment type

Namespace:

using EleWise.ELMA.API;
using EleWise.ELMA.Documents.Managers;

Script text:

var AppGroup = ApprovementTaskGroupManager.Instance.GetGroupsByDocument(context.Document).LastOrDefault();
if (AppGroup != null)
{
    context.Attachment = PublicAPI.Docflow.Objects.Tasks.ApprovementList.ApprovementListToPdf(context.Document);
}