Wednesday, February 20, 2013

CDC Software Pivotal CRM 6.0: How to execute another client task method with parameters.

Yes it is possible to call another client task method with parameters.
It can be useful for specific things like using Client Forms as custom dialogs.

The caller:
// Get action service
IActionService actionService = ClientContext.ClientAPIService.GetService<IActionService>();

// Create action target object
IClientTaskActionTarget clientTaskActionTarget = actionService.CreateActionTarget<IClientTaskActionTarget>();
clientTaskActionTarget.ClientTask = "MyCompany.PivotalProject.Client";
clientTaskActionTarget.ClientTaskMethod = "MyMethod";
clientTaskActionTarget.Parameters = new object[] { 
 "parameter 1", "parameter 2", "parameter 3"
};

// Create action and execute it.
IAction action = actionService.CreateAction("MyActionName", ActionCommand.Show, ActionContent.ClientTask, clientTaskActionTarget);
actionService.ExecuteAction(action);
The calling method:
public void MyMethod(string p1, string p2, string p3){
 // ... Do something
}