AddEvent(_event: IBProcessEvent);
_event. The event that should be added.
The AddEvent method adds the specified event to the corresponding group of collection events.
The event is added to the group according to its type.
Executing the example requires that the repository contains a process with the PROCESS identifier and a unit with the M_PROCESS_EVENTS identifier. The unit contains the OnStart and OnBeforeSendMailMessage methods used for handling process events.
Add links to the BPM, Metabase system assemblies. Add a link to the assembly that is required to work with processes.
Sub UserProc;
Var
Mb: IMetabase;
MObj: IMetabaseObjectDescriptor;
Process: IBProcess;
EventCollection: IBProcessEventGroupCollection;
ForeEvent: IBProcessEventMethod;
MailEvent: IBProcessEventEmail;
Email: IBProcessEmail;
Begin
Mb := MetabaseClass.Active;
MObj := Mb.ItemById("PROCESS");
// Get process structure
Process := BProcessCollection.EditByKey(MObj.Key);
// Get the collection of groups of process events
EventCollection := Process.Events;
// Create an event of Fore method execution on process start
ForeEvent := New BProcessEventMethod.Create(BProcessEventType.StartProcess, "ForeEvent");
EventCollection.AddEvent(ForeEvent);
ForeEvent.Method := New BPForeMethodLink.CreateNew(Mb.ItemById("M_PROCESS_EVENTS"), "OnStart");
// Create an event of email sending on process finish
MailEvent := New BProcessEventEmail.Create(BProcessEventType.FinishProcess, "MailEvent");
EventCollection.AddEvent(MailEvent);
Email := MailEvent.Email;
Email.Recipient := "first@mail.ru";
Email.CCRecipient := "two@mail.ru";
Email.BCCRecipient := "blind@mail.ru";
Email.Subject := "Finish process execution";
Email.Message := "Process is finished, check work results.";
Email.IsBodyHtml := True;
Email.OnBeforeSend := New BPForeMethodLink.CreateNew(Mb.ItemById("M_PROCESS_EVENTS"), "OnBeforeSendMailMessage");
// Save changes
If ForeEvent.IsValid And MailEvent.IsValid Then
Process.Save;
End If;
End Sub UserProc;
After executing the example two events are created for the process: Fore method will be executed on process start, an email is sent on process finish. The necessary settings will be determined for the events.
See also: