Retrieve single DynamicContent item
I'm relatively new to working with DynamicContent and I'm wondering how to retrieve a single DynamicContent item when you don't know it's ID, only a FieldValue, Title, for example? The GetDataItem method expects and ID, so I was trying to use GetDataItems like this:
Type officeLocationType = TypeResolutionService.ResolveType(
"Telerik.Sitefinity.DynamicTypes.Model.OfficeLocations.OfficeLocation"
);
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
var loc = dynamicModuleManager.GetDataItems(officeLocationType).Where(i => i.GetValue<IList>(
"Title"
).Equals(
"Philadelphia"
)).FirstOrDefault();
Under Administration >> Module Builder
Select your module. Then on the right there is a Code Reference link which will get you exactly what you need. Should be something similar to this.
var myFilteredCollection = dynamicModuleManager.GetDataItems(officeLocationType).Where(i => i.GetValue<
string
>(
"Title"
) ==
"Philadelphia"
).FirstOrDefault();
Hi,
The sample query from Jonathan is the solution to the case the need to call GetValue<T>("FieldName") is due to the fact that in module builder there is no predefined fields available for each item one module can have Title field, but other module might have "SportID" field instead so its up to the user to enter the names for fields chosen in the module.
Regards,
Stanislav Velikov
Telerik