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
}

Wednesday, January 9, 2013

CDC Software Pivotal CRM 6.0: Adding custom button to buttons bar.

Someone asked me today how to add custom button bar button to a client form.
Very simple :)

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

// Create client task action target
IClientTaskActionTarget clientTaskActionTarget = actionService.CreateActionTarget<IClientTaskActionTarget>();
clientTaskActionTarget.ClientTask = "Pivotal.Client.FormTask";
clientTaskActionTarget.ClientTaskMethod = "CustomButtonClickHandler";

// Create action            
IAction action = actionService.CreateAction("CustomButtonClickActionName", ActionCommand.Show, ActionContent.ClientTask, clientTaskActionTarget);

// Create custom button (requires Pivotal.Engine.UI.DataTypes.dll)
ButtonBarButton button = new ButtonBarButton(){
 Name = "CustomButton",
 DisplayName = "My Custom Button",
 Enabled = true
};

// Set custom button action
button.SetAction(action);

// Add custom button to a center content buttons bar
this.ButtonBar.Buttons.Add(button);