logo

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 with PublicAPI

Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA up to 3.12.1 inclusive.

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");

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.Director; //write participant from a User type variable
evnt.EventUsers.Add(user); //add participant to the event
evnt.Subject="Subject";
evnt.StartDate=context.StartDate.Value; //start date
evnt.Place="Place";
evnt.EndDate=context.EndDate.Value;//end date
evnt.Save();