logo

Weekly Check of Contacts’ Birthdays; Assigning Corresponding Tasks to Responsible Employees

This article describes how to implement a weekly check of upcoming birthdays of people from the contact list.

If there is a birthday, the user who is responsible for that contact is assigned a corresponding task.

In order for the business process to start every week, set the trigger of the start event to Timer. In the timer settings, set it to trigger once a week on a certain day. To get a list of contacts with birthdays and create corresponding tasks use the script given below.

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.List – Contact type variable with the List relationship type

Namespace:

1	using EleWise.ELMA.API;

Script text:

1 var contractors = PublicAPI.CRM.Contractor.Find(FetchOptions.All).ToList();
2 contractors.ForEach(contr =>{
3  var contacts = contr.Contacts.ToList(); //check all contacts in each contractor
4  contacts.ForEach(c =>{
5   if ((c.Birthday != null)&(contr.Responsible != null)) //select contacts that have a 
6 birthday and a responsible employee specified
7   {
8    if ((c.Birthday.Value.DayOfYear > context.WorkflowInstance.StartDate.Value.DayOfYear)&
9                                                (с.Birthday.Value.DayOfYear < 
10 (context.WorkflowInstance.StartDate.Value.DayOfYear + 7))) //select contacts whose birthday is on the weel following process start 
11 
12    {
13        //to display the list, add the contact to a context variable 
14
15         //"Contact" type with the "List" relationship type    
16         context.List.Add(k);
17         //create a task and fill in all required fields
18         var tsk = PublicAPI.Portal.TaskBase.Task.Create();
19                                                       
20         // you can specify any user as task author 
21          tsk.CreationAuthor = contr.Responsible;
22          tsk.CreationDate = DateTime.Now;
23          // depending on the due date, you can specify another task end date
24          tsk.EndDate=DateTime.Now.AddDays(1);
25          // as task executor, specify the employee resposible for the contractor
26          tsk.Executor = contr.Responsible;
27          // in the task subject specify whose birthday it is, and who is reponsible for
28           the conrtactor to whom the contact belongs
29          tsk.Subject = "Birthday of" + “c.Name” + " from " + contr.Name;
30          tsk.Description = " Any task description ";
31          tsk.Save();
32    }
33   }
34    });
35   });

Script without PublicAPI

For the script to work, connect the following assemblies:

Elewise.ELMA.Project

Elewise.ELMA.Documents

Elewise.ELMA.Documents.Docflow

Elewise.ELMA.Tasks

Namespaces:

1 using EleWise.ELMA.CRM.Models;
2 using EleWise.ELMA.Model.Common;
3 using EleWise.ELMA.Model.Managers;
4 using EleWise.ELMA.Tasks.Models;
5 using EleWise.ELMA.Tasks.Managers;
6 using EleWise.ELMA.Model.Services;

 Script text:

//check all contractors
var contractors = EntityManager<Contractor>.Instance.Find(FetchOptions.All);
contractors.ForEach(kontr =>{
//view the list of contacts of each contractor
  var contacts = kontr.Contacts.ToList();
  contacts.ForEach(k =>{
  //select only the contacts, for which a birthday and a responsible user are specified
    if ((k.Birthday != null)&(kontr.Responsible != null))
    {
//select only the contacts, whose birthday is within a week from the process start date                                     
        if ((k.Birthday.Value.DayOfYear > context.WorkflowInstance.StartDate.Value.DayOfYear)&
        (k.Birthday.Value.DayOfYear < (context.WorkflowInstance.StartDate.Value.DayOfYear + 7)))
          {
          //if you need to display the obtained list, add the contact to a context variable
      //of the Contact type with the List link type                                    
      context.List.Add(k);
      //create a task and fill in all the required fields
          var tsk = InterfaceActivator.Create<Task>();               
      //you can specify any user as the task author                                     
          tsk.CreationAuthor = kontr.Responsible;
          tsk.CreationDate = DateTime.Now;
          //depending on the date, you can specify another task due date
          tsk.EndDate=DateTime.Now.AddDays(1);
          //specify the user responsible for the contractor as the task executor
          tsk.Executor = kontr.Responsible;
          //in the task subject, specify who has a birthday and to which contractor this contact belongs
          tsk.Subject = "Birthday of " + k.Name + " from " + kontr.Name;
          tsk.Description = "Any task description";
          tsk.Save();
       }
     }
  });
});