logo

Changing document life cycle stages in a script

To change a document life cycle stage in a script, you need to set a value of the LifeCycleStatus type to the Status field of the document.

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.Document - variable of the Document type

Namespace:

using EleWise.ELMA.API;

Script text:

var lcs = PublicAPI.Docflow.Objects.LifeCycleStatus.Find(FetchOptions.All).Where(c => c.Name == "Start").FirstOrDefault();
            if (lcs != null)
            {
                PublicAPI.Docflow.Document.ChangeStatus(context.Document, lcs);
            }  

Script without PublicAPI

For the script to work correctly, add the following assemblies:
EleWise.ELMA.Documents
EleWise.ELMA.Documents.Docflow

Namespaces:

using EleWise.ELMA.Documents.Models;
using EleWise.ELMA.Model.Managers;

Script text:

LifeCycleStatus new_status = null;
var statusFilter = InterfaceActivator.Create<Filter>();
statusFilter.Query = "Name LIKE ’Start’";
//search the required document life cycle status
new_status = EntityManager<LifeCycleStatus>.Instance.Find(statusFilter, null).FirstOrDefault();
//change the document status
if (new_status != null) context.Doc.Status = new_status;
//save the new document status
context.Doc.Save();