Scripts triggered by events
1. Script for processing the Create new document event
This is an example of a script for processing the document creation event. The script is started after the user clicks Save when creating a document. The script will save the Sender attribute value in the Description attribute. A document of the Fax type with the Sender attribute of the Contractor type will be used. Add the script to a separate object. Create a new object without properties for this purpose.
For the script to work, add the global assembly
NHibernate
and namespaces:
using EleWise.ELMA.Documents.Models;
using EleWise.ELMA.Runtime.Managers;
using EleWise.ELMA.Runtime.NH.Listeners;
using EleWise.ELMA.ConfigurationModel;
using EleWise.ELMA.ComponentModel;
using NHibernate.Event;
Script text:
[Component]
public class ReSaveNameDoc : PostFlushEventListener
{
// object/document creation event
public override void OnPostInsert(PostInsertEvent @event)
{
// Identify the document type
//----------------------------------------------------------
if(@event.Entity is IDocFax) // Fax document interface
{
var TMPDoc = (IDocFax)@event.Entity; // cast to the type
if(TMPDoc.Sender!=null)
{ // fill in the Description attribute
TMPDoc.Description = "From " + TMPDoc.Sender.Name.Trim();
}
}
}
}
2. Script for processing the Edit document event
This is an example of a script for processing the document editing event. The script is started after a user clicks Save having edited a document. The script will add "The document has been edited" to the Description attribute.
Script text:
// object/document editing event
public override void OnPostUpdate(PostUpdateEvent @event)
{
// Identify the document type
//----------------------------------------------------------
if(@event.Entity is IDocFax) // Fax document interface
{
// cast to the type
var TMPDoc = (IDocFax)@event.Entity;
// fill in the Description attribute
TMPDoc.Description = "The document has been edited " + DateTime.Now.ToString();
}
}