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 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.Ispolnitelj; //specify the executor
wl.WorkMinutes = 1000; //time spent (in minutes)
wl.Save();
 
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here

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.