Selecting default data source of a form

Vote:
 

Hello,

I have a custom form container that is inherited from FormContainerBlock. How do I set its default data source to an existing implementation of IExternalSystem? I want every instance of this form container should have the default data source. 

#201980
Mar 11, 2019 11:51
Vote:
 

Hi Hüseyin

You should be able to set the value of Forms_ConnectedDataSource on all FormContainerBlock types in the ContentCreating event in an Episerver Intialisation module.

https://world.episerver.com/documentation/class-library/?documentId=cms/11/81F308A 

https://world.episerver.com/documentation/developer-guides/CMS/initialization/ 

David

#201981
Mar 11, 2019 12:20
Vote:
 

Hello David,

Thanks for your answer. It is possible to get the form container during an initialisation script by casting e.Content to the form container. However, the form block does not contain any property for ConnectedDataSource. Am I looking at the wrong place?

private void OnCreatingContent(object sender, ContentEventArgs e)
{
    if (!(e.Content is CustomFormContainer customFormContainer)) return;
 
    sbgFormContainer. //The object does not expose ConnectedDataSource
}
#201984
Mar 11, 2019 12:52
Vote:
 

Hi Hüseyin

Its not exposed as a strongly typed property but you should be able to access it using the property collection. Something like:

((CustomFormContainer)sbgFormContainer).Property["Forms_ConnectedDataSource"] = <<your value here>>

David

#201985
Mar 11, 2019 12:55
Vote:
 

Hi, thanks for the tip!

I see, the property accepts a PropertyConnectedDataSourceCollection object. Is it okay to initiate this only using the ID value? Otherwise, how can I create this object? One alternative can be to hold an instance where I copy the properties from, are there any other ways. 

#201988
Mar 11, 2019 13:15
Vote:
 

The collection extends PropertyLongString so you could look at the string value on a configured form and set that in your init module

#201989
Mar 11, 2019 13:52
Vote:
 

Hi, unfortunately this did not make any effect.

#202112
Mar 14, 2019 13:50
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.