Retrieve RelatedItem Custom Field From Events Module

Posted by Community Admin on 04-Aug-2018 15:15

Retrieve RelatedItem Custom Field From Events Module

All Replies

Posted by Community Admin on 10-Mar-2016 00:00

I have added a Custom Field named "MyImage" to Events Module. 

I need to retrieve it from code behind. How can I do that? My RelatedMedia field is basically an Image that i want to retrieve for an Event.

I was hoping something  like this would work, but it doesn't:

    var mgr = EventsManager.GetManager();

   Event ev = mgr.GetEvents().Where(e => e.UrlName == urlName).FirstOrDefault();

   var photo =   obj.GetValue("MyImage");

 

MyImage is a custom field of type RelatedMedia (Image) added in the Events module through the Events Content page(Right hand menu).

Kindly help, I am stuck with this for hours.

Posted by Community Admin on 12-Mar-2016 00:00

Anyone?

Posted by Community Admin on 15-Mar-2016 00:00

Hello,

It is unclear in your small code snippet what "obj" is in obj.GetValue("MyImage").

The following sample worked for me to retrieve the related image and it's info.

EventsManager mgr = EventsManager.GetManager();
  
Event eventItem = mgr.GetEvents().FirstOrDefault();
  
eventItem = mgr.Lifecycle.GetLive(eventItem) as Event;
  
var imageField = eventItem.GetRelatedItems<Telerik.Sitefinity.Libraries.Model.Image>("MyImage").SingleOrDefault();
  
var imageurl = imageField.Url;
var imageid = imageField.Id;
  
LibrariesManager librariesManager = LibrariesManager.GetManager();
Telerik.Sitefinity.Libraries.Model.Image image = librariesManager.GetImages().Where(i => i.Id == imageid).FirstOrDefault();
  
if (image != null)
    image = librariesManager.Lifecycle.GetMaster(image) as Image;

You may also want to take a look at the following article regarding querying images: http://docs.sitefinity.com/for-developers-query-images
and about the Related data API: http://docs.sitefinity.com/for-developers-related-data-api
Related data API examples: http://docs.sitefinity.com/example-related-datarelated-data-api-examples

Regards,
Dimitri Cools
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 15-Mar-2016 00:00

Dimitri, 

   Thanks alot for replying. I tried your approach, But I am unable to call GetRelatedItems method on eventItem. There is no method available named GetRelatedItems on Event object. 

Also, in my initial question 'obj' is 'Event' i.e eventItem.

Please see the attached screenshot. Why am I not getting the GetRelatedItems method through Event's object.

 

GetRelatedItems<>() is however available using EventsManager's object. But, its takes too many values as parameters (Screenshot2 attached) & I am not sure what values to pass to it. 

Thanks, Looking forward to your response.

Posted by Community Admin on 16-Mar-2016 00:00

Hello,

Please make sure you add the following using statement:

using Telerik.Sitefinity.RelatedData;

Here is a screenshot for your reference: http://screencast.com/t/HcCr2dSp

Regards,
Dimitri Cools
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 18-Mar-2016 00:00

Well, thats embarassing. I tried Control+Dot on it but it wouldn't come up in intellisense. 

Thanks for the help man. 

 

This thread is closed