Creating a time report on a task using a script

This article provides examples of scripts for creating and saving a time report on a specific task.

Script with PublicAPI

Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA 3.12.1 or lower.

Context variable:

context.Task - variable of the Task type

Namespace:

using EleWise.ELMA.API;
 

Script text:

PublicAPI.Portal.TaskBase.SetFactWorkLog(context.Task.Id, 1000, DateTime.Now, "comment to the time report"); //set the actual time spent in Minutes 1000 minutes
//PublicAPI.Portal.TaskBase.SetFactWorkLogDays(context.Task.Id, 1, DateTime.Now, "comment to the time report"); //set the actual time spent in Days 1 day
//PublicAPI.Portal.TaskBase.SetFactWorkLogHours(context.Task.Id, 1, DateTime.Now, "comment to the time report"); //set the actual time spent in Hours 1 hour
 

After the script execution, the Time Report Log tab with a new time report item will be added to the page of the task, stored in the context variable.

Script without using PublicAPI.

Assume the task is stored in the context.Task context variable.

For the script to work correctly, add namespaces:

using EleWise.ELMA.Tasks.Models;
using EleWise.ELMA.Model.Services;
 

Script:

var wl =  InterfaceActivator.Create<WorkLog>(); //create a new time report item
wl.Comment = "comment to the time report"; //add a comment
wl.CreationAuthor = context.Author; //specify the author
wl.StartDate = DateTime.Now; //start date
wl.TaskBase = context.Task; //specify the task
wl.Worker = context.Executor; //specify the executor
wl.WorkMinutes = 1000; //time spent (in minutes)
wl.Save();