Creating an event in a process with a script

In this article, we show how you can use a script to create an event in the Calendar.

Script without PublicAPI.

You need the following assemblies:

Elewise.ELMA.Documents
Elewise.ELMA.Calendar

Namespaces:

using EleWise.ELMA.Calendar.Models;
using EleWise.ELMA.Security.Services;
using EleWise.ELMA.Model.Services;

Script text:

var evnt =  InterfaceActivator.Create<CalendarEvent>(); //create new event
evnt.CreationDate=DateTime.Now; //creation date
evnt.CreationAuthor=AuthenticationService.GetCurrentUser<EleWise.ELMA.Security.Models.User>(); //the author is the current user
evnt.Description="Event description";
var user= InterfaceActivator.Create <CalendarEventUser>(); //Create event participant
user.User=context.Direktor; //write participant from a User type variable
evnt.EventUsers.Add(user); //add participant to the event
evnt.Subject="Subject";
evnt.StartDate=context.DataNachala.Value; //start date
evnt.Place="Place";
evnt.EndDate=context.DataOkonchaniya.Value;//end date
evnt.Save();
Creating a similar script with PublicAPI
Updated documentation on PublicAPI is available here.

Context variables:

context.Users - User type variable, link type - list
context.StartDate - Date/Time variable
context.EndDate - Date/Time variable

Namespace:

using EleWise.ELMA.API;
Script text:
PublicAPI.Portal.CalendarEvent.Create(context.Users, context.StartDate.Value, context.EndDate.Value, "Subject", "Place");
​