+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Retrieve RelatedItem Custom Field From Events Module

Retrieve RelatedItem Custom Field From Events Module

6 posts, 0 answered
  1. Zepp
    Zepp avatar
    22 posts
    Registered:
    19 Aug 2015
    10 Mar
    Link to this post

    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.

  2. Zepp
    Zepp avatar
    22 posts
    Registered:
    19 Aug 2015
    12 Mar in reply to Zepp
    Link to this post
    Anyone?
  3. Dimitri Cools
    Dimitri Cools avatar
    80 posts
    Registered:
    27 Sep 2016
    15 Mar
    Link to this post
    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
     
  4. Zepp
    Zepp avatar
    22 posts
    Registered:
    19 Aug 2015
    15 Mar in reply to Dimitri Cools
    Link to this post

    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.

  5. Dimitri Cools
    Dimitri Cools avatar
    80 posts
    Registered:
    27 Sep 2016
    16 Mar
    Link to this post
    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
     
  6. Zepp
    Zepp avatar
    22 posts
    Registered:
    19 Aug 2015
    18 Mar in reply to Dimitri Cools
    Link to this post

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

    Thanks for the help man. 

     

6 posts, 0 answered