Said Ait Haddou Ali
Read all my blogsIn 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:
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;
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:
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:
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.
3 responses to “Automated task creation from Customer in C4C”
Hi Said, nice blog! Pretty sure though it has nothing to do with BOPF 😉 (maybe you should alter your labels)
Best, Sander
Hi Sander, great to hear from you and get your feedback! I applied a small change. Thanks for the heads up.
Regards,Said
Great article Said !