Sunday, November 25, 2012

CDC Software Pivotal CRM 6.0: Using Pivotal Input Dialog.


Pivotal Input Dialog may be useful if you want to ask user some input parameters without creating a new client form.
I didn't find any documentation about how exactly to use Pivotal Input Dialog.
So I'm going to publish some code examples here how to use it.

Required dlls:

Pivotal.Engine.Client.Services.Interfaces.dll
Pivotal.Engine.UI.DataTypes.dll

// Get input dialog service
IInputDialogService inputDialogService = ClientContext.ClientAPIService.GetService<IInputDialogService>();
DialogParam dialogParameter = new DialogParam();
dialogParameter.FormParams = new CdcSoftware.Pivotal.Engine.UI.DataTypes.FormParams.InputParamsCollection();

// 1. Foreign Key
Table companyTable = this.SystemClient.UserProfile.GetMetaItem<Table>("Company");
InputParam foreignKeyInputParam = new InputParam()
{
    Label = "Company",
    Type = InputParamType.RForeignField,
    IsRequired = true,
    Enums = companyTable.Id
};
dialogParameter.FormParams.Add(foreignKeyInputParam);

// 2. Single value fields: Date, Boolean, Integer, Double and etc
InputParam dateInputParam = new InputParam() { Label = "Date", Type = InputParamType.Date };
dialogParameter.FormParams.Add(dateInputParam);

InputParam boolInputParam = new InputParam() { Label = "Boolean", Type = InputParamType.Boolean };
dialogParameter.FormParams.Add(boolInputParam);

InputParam intInputParam = new InputParam() { Label = "Integer", Type = InputParamType.Integer };
dialogParameter.FormParams.Add(intInputParam);

// 2. Combo, ListBox
object[] comboValues = new object[] { "value 1", "value 2" };
InputParam comboInputParam = new InputParam() { Label = "Date", Type = InputParamType.RCombo, Enums = comboValues };
dialogParameter.FormParams.Add(comboInputParam);

// Set dialog type
dialogParameter.DialogType = ModalDialogTypeEnum.modalDialogParamsAndDescription;

// Show dialog
inputDialogService.ShowDialog(dialogParameter, "Title");

// Get parameter values
if (foreignKeyInputParam.Value != null)
{
    Id companyId = Id.Create(foreignKeyInputParam.Value);
}

if (intInputParam.Value != null)
{
    int intValue = TypeConvert.ToInt32(intInputParam.Value);
}
You can discover other input parameters types by yourself.