Script for getting document approval results

This is article provides an example of a script for getting the approval result comment. The script uses context variables:
context.Doc - variable of the Contract type
context.Comment - variable of the Text type

Script with PublicAPI

Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA up to 3.12.1 inclusive.
var harm = PublicAPI.Docflow.Tasks.GetApprovementGroupsByDocument(context.Doc); //get all the approval tasks of this document
context.Comment = "";
foreach(var i in harm.ToList())
{ 
                  
    foreach(var j in i.ApprovementList.Items.ToList())
    {
        foreach(var res in j.Results.ToList())
        {
            context.Comment+= res.Item.User.FullName + " " + res.Item.SolutionDate + "\n"; 
            foreach (var cm in res.Item.Comment.ToList())
            {
                context.Comment+= cm.ToString();
            }
            context.Comment+= "\n";
        }
    }
}​

Script without PublicAPI

Add the following assemblies:
Elewise.ELMA.Documents
Elewise.ELMA.Documents.Docflow
 
Namespaces:
using EleWise.ELMA.Documents.Managers;
Script text:
var approvalGroups = ApprovementTaskGroupManager.Instance.GetGroupsByDocument(context.Doc); //get all the approval tasks for this document
            context.Comment = "";
            foreach (var grp in approvalGroups)
            {
                foreach (var item in grp.ApprovementList.Items)
                {
                    foreach (var res in item.Results)
                    {
                        context.Comment += res.Status.ToDescription() + " " + res.Item.User.FullName + " " + res.Item.SolutionDate;
                        if (String.IsNullOrEmpty(res.Item.Comment) == false)
                            context.Comment += " \"" + res.Item.Comment + "\"";
                        context.Comment += "\n";    
                    }
                }
            }
 
Note
Starting with ELMA 3.12.0, it is possible to check which outgoing transition was used to exit the approval process task. The UID of the selected transition is saved in the database, in the approval sheet item (ApprovementListItem), in the SelectedConnectorUid.
foreach (var item in grp.ApprovementList.Items)
{
  var uid = item.SelectedConnectorUid; // get the UID of the transition, used to exit from the approval sheet item
}