Acorel
To Acorel.nl
Acorel background

Automated task creation from Customer in C4C

Said Ait Haddou Ali, 04 January 2017

In this scenario the requirement is to automatically create Activity Tasks for customers when certain conditions are met. For example, the business partner is still a Prospect. Also, part of the requirement is to assign the task to a certain employee from the Account Team.

Normally, this would be a nice opportunity to make use of the workflow capabilities in C4C. The advantage would be that you give the business user control in defining rules to configure the conditions for which an Activity Task will be created automatically. In order for this to work, the developer is required to create an action linked to the Customer BO, so that the action will be available for selection during workflow creation. Unfortunately, the Customer BO extension does not support actions (or associations and other node extensions). Trying to create an action in the Customer BO extension results in an error message:

Apparently, the Customer BO is not created in the Enterprise Service Framework Layer (ESF2), making custom actions for the customer BO not an option. For your reference, a list standard BOs that do support custom actions and node extensions can be found here.

With this in mind our avenue of approach for our current requirement will be to use the standard BeforeSave event in the Customer BO extension. Using this event, our logic will be triggered at the correct moment, but the development needs to be done in the SDK.

So in order to fulfill our requirement of mimicking a workflow and creating a task assigned to a specific employee, we basically need the following three components:

1. Define the condition when the task needs to be created. For example, if we are dealing with a prospect. This can be done by evaluating the customer role. We also evaluate whether there has already been a task created as we do not want to end up creating a task every time the prospect is saved. A KeyUserTool field is used to check this.

if ( this.CustomerRole.RoleCode.content == “BUP002”

&& his.CurrentCommon.Z_TaskCreated = false) {

}

2. When the condition is fulfilled, we need to create a task. In this case it is a simple task, but properties like due dates can be provided as well. We also set the flag signifying a task has been created:

//Activity: Root node
var elActivityRoot : elementsof Activity;
var instActivity;

// Activity: define party node
var elActivityParty : elementsof Activity.Party;
var instParty;
elActivityRoot.SubjectName = “Automated task”;

// Activity: set task category
elActivityRoot.GroupCode.content = “0001”; //visit

// Activity: create new instance
instActivity = Activity.Create(elActivityRoot);

// Link task to our business partner
elActivityParty.PartyName = this.InternalID;
instActivity.MainActivityParty.Create(elActivityParty);

//Set task created flag
this.CurrentCommon.Z_TaskCreated = true;

3. We need to be able to assign the task to an employee, specified by the business user. In C4C the business user can add parties involved in the Account Team:

Let’s say that the party with role Account Manager should be the person the created task should be assigned to. We add this user to the Account Team:
Now in the SDK we can read the Account team information through node CurrentEmployeeResponsible:

var accman = cust.CurrentEmployeeResponsible.Where(n=> n.PartyRoleCode == “Z08”);

Adding the account manager as processor to the task will result in him being the person the task is assigned to. So we add the account manager as processor to the task:

if ( accman.Count() > 0 ){

elActivityParty.PartyName = accman.GetFirst().EmployeeID.content;
instActivity.ProcessorParty.Create(elActivityParty);

}

There is a standard process in place that defaults the processor party to the user that performed the save of the customer. With the newly created processor the default processor is redundant and needs to be deleted:

foreach ( var actparty in instActivity.Party ) {

//remove redundant processorif actparty.RoleCode == “40” && actparty.Party.Employee.Identification.GetFirst().EmployeeID.content != servresp.GetFirst().EmployeeID.content){

actparty.Delete();

}

}

The result:

Similarly, the contactperson and the employee responsible can be changed.

To wrap up…

The customer.xbo does not support workflows with custom actions but we are able to obtain the same result by using the BeforeSave event in the SDK. We can create a task whenever a predefined condition is satisfied and we can maintain the involved parties for a task, controlling the property of to whom the task is assigned to.

Said Ait Haddou Ali

Read all my blogs

Receive our weekly blog by email?
Subscribe here: