Adding a comment to the current process instance with a script

To add a comment to a current process instance, you need to create a Comment class instance and add it to the list of comments using the Add() method. Then, create a corresponding event for the comment to be stored in the instance history. 

Script without PublicAPI.

For the script to work properly, add the following namespaces:
using EleWise.ELMA.Common.Models; using EleWise.ELMA.Model.Services; using EleWise.ELMA.Services; using EleWise.ELMA.Model.Events;
using EleWise.ELMA.Workflow.Models; using EleWise.ELMA.Common.ExtensionPoints; 

Script text:

//create comment
var cmnt = InterfaceActivator.Create<Comment> ();
//specify the date of comment creation
cmnt.CreationDate = DateTime.Now;
//specify comment author. Instead of the process instance initiator you can specify a different user
cmnt.CreationAuthor = context.WorkflowInstance.Initiator;
//introduce the text of the comment
cmnt.Text = "Text";
//save the comment
cmnt.Save ();
//add the comment to the instance's list of comments
context.WorkflowInstance.Comments.Add (cmnt);
//create an event for adding it to the instance history
var ActionHandler = Locator.GetServiceNotNull<IEntityActionHandler> ();
var commentAction = Locator.GetService<ICommentActionHandler> ();
var commentActionModel = InterfaceActivator.Create<CommentActionModel> ();
commentActionModel.Comment = cmnt;
var args = EntityActionEventArgs.TryCreate (null, context.WorkflowInstance, WorkflowInstanceActions.AddComment);
if (args != null) {
     commentAction.ProcessEventArgs (args, commentActionModel);
     ActionHandler.ActionExecuted (args);
}
Creating a similar script with PublicAPI
Updated documentation on PublicAPI is available here.

Namespace:

using EleWise.ELMA.API;

Script text

PublicAPI.Processes.WorkflowInstance.AddComment(context.WorkflowInstance, "Text"); //Comment author - current user, Send on - current date

: