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

Forums / Developing with Sitefinity / Getting Custom Fields from Events

Getting Custom Fields from Events

10 posts, 1 answered
  1. Dexterously
    Dexterously avatar
    3 posts
    Registered:
    20 Jul 2012
    04 Jan 2012
    Link to this post
    We added a custom field to the events form when creating it. The field is a boolean value.

    How can we get it programmatically?
  2. Tim
    Tim avatar
    258 posts
    Registered:
    22 Jun 2011
    04 Jan 2012
    Link to this post
    Oscar,

    If you add a reference to Telerik.Sitefinity.Model you'll have access to .GetValue.

    If you're using the Fluent API, here is a code example I found for you.

    Hope that helps!
  3. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    08 Jan 2012
    Link to this post
    Hi guys,

    @Oscar, just like @Tim said, you need to use the GetValue() method. Take a look at the following sample:
    var eventItem = App.WorkWith()
                    .Events()
                    .Where(t => t.Status == ContentLifecycleStatus.Live)
                    .Where(t => t.GetValue<bool>("customField") == true)
                    .Get();


    Kind regards,
    Jen Peleva
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
    Answered
  4. Dustin
    Dustin avatar
    14 posts
    Registered:
    14 Jun 2011
    09 Jan 2012
    Link to this post
    Hi Jen,

    I am trying to query for a user based on a value in a custom field in the user profile. Is this possible using code similar to what you posted for the Events object? It appears as though I need to get the user profile of a specific user before I can check the value of the custom user profile field. I would like to try to avoid that since we'll have a large number of users in the system and it would be very inefficient.

    Thanks for your help.

    Dustin
  5. Dexterously
    Dexterously avatar
    3 posts
    Registered:
    20 Jul 2012
    09 Jan 2012
    Link to this post
    Just make sure you include this namespace:
    using Telerik.Sitefinity.Model;

    Since GetValue<> is an extension method.
  6. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    11 Jan 2012
    Link to this post
    Hello Dustin,

    Take a look at this forum thread. I believe you might find it useful.

    All the best,
    Jen Peleva
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  7. Dustin
    Dustin avatar
    14 posts
    Registered:
    14 Jun 2011
    11 Jan 2012
    Link to this post
    Hi Jen,
    Thank you for your reply. I looked at the thread you suggested, but I'm not sure that it provides a workable solution. The first suggestion in that thread was to use linq to query a user profile, but I don't know who the user is until I've matched the custom field in the profile. The second suggestion was to get all users in the database and then loop through their profiles until finding the matching custom field value. This solution seems very inefficient since we will have tens of thousands of users.

    I would like to do something similar to what Victor had suggested in the other thread, but without knowing the user ahead of time. Here's an example of what I would like to do (notice I do not pass a user).

    var pm3 = App.WorkWith().UserProfiles().UserProfiles().Where(uP => uP.GetValue<String>("ThirdPartySystemKey") == "12345");

    Is there any way to accomplish something similar to the above code?

    Thank you,
    Dustin
  8. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    13 Jan 2012
    Link to this post
    Hello Dustin,

    Unfortunately, If you don't know the user, the only possible approach would be looping through the profiles and finding the matching users.

    Regards,
    Jen Peleva
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  9. gopalraman gopal
    gopalraman gopal avatar
    52 posts
    Registered:
    03 Dec 2009
    11 Apr 2012
    Link to this post
    Hi,

    I am trying to filter the news item by following method, i have a custom field called "ArticleDate" as DateTime field

      var vNews = App.WorkWith().NewsItems()
                                   .Where(newsItem => newsItem.Status == ContentLifecycleStatus.Live)
                                  .Where(newsItem => newsItem.GetValue<DateTime>("ArticleDate") != null)
                                  .Where(newsItem => newsItem.GetValue<DateTime>("ArticleDate").Year == 2012)
                                   .Get().ToList();

    but i am receiving the following error please can u help me over this?

    "An exception occured during the execution of '
    Extent<Telerik.Sitefinity.News.Model.NewsItem>().Where(b => (b.ApplicationName == value(Telerik.Sitefinity.Modules.News.Data.OpenAccessNewsProvider+<>c__DisplayClass5).appName)).Where(newsItem => (Convert(Convert(Convert(Convert(Convert(Convert(Convert(newsItem.Status))))))) == 2)).Where(newsItem => (Convert(newsItem.FieldValue("ArticleDate")) != Convert(null))).Where(newsItem => newsItem.FieldValue("Category").Any(item => item.Equals(value(Telerik.Sitefinity.Data.Linq.OpenAccess.OpenAccessExpressionVisitor`2+<>c__DisplayClassa[Telerik.Sitefinity.News.Model.NewsItem,Telerik.Sitefinity.News.Model.NewsItem]).comparingObject)))'. See InnerException for more details."

    Thanks


  10. gopalraman gopal
    gopalraman gopal avatar
    52 posts
    Registered:
    03 Dec 2009
    11 Apr 2012
    Link to this post
    Hi,

    I am trying to filter the news item by following method, i have a custom field called "ArticleDate" as DateTime field

      var vNews = App.WorkWith().NewsItems()
                                   .Where(newsItem => newsItem.Status == ContentLifecycleStatus.Live)
                                  .Where(newsItem => newsItem.GetValue<DateTime>("ArticleDate") != null)
                                  .Where(newsItem => newsItem.GetValue<DateTime>("ArticleDate").Year == 2012)
                                   .Get().ToList();

    but i am receiving the following error please can u help me over this?

    "An exception occured during the execution of '
    Extent<Telerik.Sitefinity.News.Model.NewsItem>().Where(b => (b.ApplicationName == value(Telerik.Sitefinity.Modules.News.Data.OpenAccessNewsProvider+<>c__DisplayClass5).appName)).Where(newsItem => (Convert(Convert(Convert(Convert(Convert(Convert(Convert(newsItem.Status))))))) == 2)).Where(newsItem => (Convert(newsItem.FieldValue("ArticleDate")) != Convert(null))).Where(newsItem => newsItem.FieldValue("Category").Any(item => item.Equals(value(Telerik.Sitefinity.Data.Linq.OpenAccess.OpenAccessExpressionVisitor`2+<>c__DisplayClassa[Telerik.Sitefinity.News.Model.NewsItem,Telerik.Sitefinity.News.Model.NewsItem]).comparingObject)))'. See InnerException for more details."

    Thanks


10 posts, 1 answered