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 with 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 without using 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:

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

 

Creating a similar script using PublicAPI

All recent documentation on PublicAPI is available here.

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);
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 = ccontr.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   });