Hi,
I'm trying to add a dropdown to the connectorsSettings section in the form builder using FormsConnectorDefinitionsExtender.
My field gets added but only the first choice is rendered and is rendered as a check box. I can see it in the backend and see the choices.
If i modify another built in field like restrictions, by changing it from a radiobutton to a dropdown, that renders correctly but my field does not.
.net framework 4.8 - sf v15.3
The full code is below and I'm running it in a brand new project setup, no other modifications or customizations exist apart from a dynamic module. Note that the screenshot provided is missing choices as i have been trying different things...
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped;
}
private void Bootstrapper_Bootstrapped(object sender, EventArgs e)
{
ObjectFactory.Container.RegisterType<FormsConnectorDefinitionsExtender, CrmWorkflowConnectorExtender>("CrmWorkflowConnectorExtender");
ObjectFactory.Container.RegisterType<IModuleConnectionStatus, CrmWorkflowConnectorExtenderConnectionStatus>(typeof(CrmWorkflowConnectorExtenderConnectionStatus).FullName, new ContainerControlledLifetimeManager());
}
}
public class CrmWorkflowConnectorExtender : FormsConnectorDefinitionsExtender
{
public override int Ordinal
{
get { return 1; }
}
public override string ConnectorName => "CrmConnectorModule";
public override string ConnectorTitle => "CRM Connector";
public override string SectionTitle => "Send data to dynamics CRM";
public override void AddConnectorSettings(ConfigElementDictionary<string, FieldDefinitionElement> sectionFields)
{
var CRMWorkflowField = new ChoiceFieldElement(sectionFields)
{
Title = "Select CRM Workflow",
FieldName = "CRMWorkflowSelection",
DataFieldName = "CRMWorkflowSelection",
DisplayMode = FieldDisplayMode.Write,
FieldType = typeof(Telerik.Sitefinity.Web.UI.Fields.ChoiceField),
RenderChoiceAs = RenderChoicesAs.DropDown,
ID = "CRMWorkflowSelectionID"
};
//foreach (var workflow in GetWorkflowDefinitions())
//{
// var choice = new ChoiceElement(CRMWorkflowField.ChoicesConfig)
// {
// Text = workflow.WorkflowName,
// Value = workflow.WorkflowName
// };
// CRMWorkflowField.ChoicesConfig.Add(choice);
//}
var mychoices = new List<ChoiceDefinition>();
mychoices.Add(new ChoiceDefinition()
{
Text = "MVCOnly",
ResourceClassId = typeof(FormsResources).Name,
Value = "0"
});
mychoices.Add(new ChoiceDefinition()
{
Text = "WebFormsOnly",
ResourceClassId = typeof(FormsResources).Name,
Value = "1"
});
CRMWorkflowField.Choices.AddRange(mychoices);
sectionFields.Add(CRMWorkflowField.ID, CRMWorkflowField);
}
private IEnumerable<WorkflowDefinitionDto> GetWorkflowDefinitions()
{
var manager = DynamicModuleManager.GetManager();
var type = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.CrmWorkflows.WorkflowDefinition");
IEnumerable<WorkflowDefinitionDto> workflows = manager.GetDataItems(type)
.Where(w => w.Status == ContentLifecycleStatus.Live && w.Visible)
.Select(w => new WorkflowDefinitionDto
{
WorkflowName = w.GetValue<string>("WorkflowName")
});
return workflows;
}
private class WorkflowDefinitionDto
{
public string WorkflowName { get; set; }
}
}
public class CrmWorkflowConnectorExtenderConnectionStatus : IModuleConnectionStatus
{
public string ModuleName => "CrmConnector.CrmConnectorModule";
public void ExecuteIfConfigured(Action action)
{
// Add code to check that the connector is connected
// ex. if (this.connector.IsConnected())
if (action != null)
action();
}
// IMPORTANT: This callback is not invoked as part of Forms connectors. You still need to implement it, as it is used elsewhere.
public void ExecuteIfNotConfigured(Action action)
{
// Add code to check that the connector is not configured
// ex. if (!this.connector.IsConnected())
if (action != null)
action();
}
}
Type : System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : ‹‹‹An item with the same key has already been added.››› Source : mscorlib Help link : ParamName : Data : ‹‹‹System.Collections.ListDictionaryInternal››› TargetSite : ‹‹‹Void ThrowArgumentException(System.ExceptionResource)››› HResult : ‹‹‹-2147024809››› Stack Trace : at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Telerik.Sitefinity.Web.Api.Strategies.Forms.Connectors.FormConnectorService.ResolveUIField(List`1 fields, FieldDefinitionElement fieldDefinitionElement, ConnectorDataMappingExtender mappingExtender, SectionFieldWrapper predecessorField) at Telerik.Sitefinity.Web.Api.Strategies.Forms.Connectors.FormConnectorService.AdjustFields(List`1 fields, SectionFieldWrapper predecessorField)