Signing a document version in a script
Consider a script which allows signing the current document version.
Script with PublicAPI
Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA up to 3.12.1 inclusive.
Context variables:
context.Director - variable of the User type
context.Document - variable of the Document type
Namespace:
using EleWise.ELMA.API;
using EleWise.ELMA.Services;
using EleWise.ELMA.Documents.Managers;
Script text
var manager = Locator.GetServiceNotNull<DocumentVersionExtManager>();
var vers = PublicAPI.Docflow.DocumentVersion.Filter().Document(context.Dokument).Status(PublicAPI.Enums.Documents.DocumentVersionStatus.Current).Find().FirstOrDefault(); // get the current document version
if (vers != null)
{
var user = PublicAPI.Docflow.Objects.DocumentAssignUser.Create();
user.User = context. Direktor;
user.DocumentVersion = vers;
vers.SignedUsers.Add(user);
manager.UpdateSimpleDigitalSignature(user);
}
Script without PublicAPI
Context variables are used in the script:
context.Document - variable of the Contract (document type) type
context.Director - variable of the User type
For the script to work, add the following assemblies:
Elewise.ELMA.Documents
Elewise.ELMA.Documents.Docflow
Namespaces:
using EleWise.ELMA.Documents.Managers;
using EleWise.ELMA.Documents.Models;
using EleWise.ELMA.Services;
Script text:
var vers = DocumentVersionManager.Instance.Get(context.Dokument.Id).ToList().Find(v => v.Status == DocumentVersionStatus.Current); //get the current document version
var manager = Locator.GetServiceNotNull<DocumentVersionExtManager>();
if (vers != null)
{
var v_sign = DocumentVersionExtManager.Instance.Load(vers.Id);
var user = DocumentAssignUserManager.Instance.Create();
user.User = context.Direktor;//specify the signatory user
user.DocumentVersion = vers;
v_sign.SignedUsers.Add(user); //add the users who signed the document to the list
manager.UpdateSimpleDigitalSignature(user);//update the digital signature information
}