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);

No comments:

Post a Comment