Getting Custom Fields from Events

Posted by Community Admin on 04-Aug-2018 03:06

Getting Custom Fields from Events

All Replies

Posted by Community Admin on 04-Jan-2012 00:00

We added a custom field to the events form when creating it. The field is a boolean value.

How can we get it programmatically?

Posted by Community Admin on 04-Jan-2012 00:00

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!

Posted by Community Admin on 08-Jan-2012 00:00

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

Posted by Community Admin on 09-Jan-2012 00:00

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

Posted by Community Admin on 09-Jan-2012 00:00

Just make sure you include this namespace:
using Telerik.Sitefinity.Model;

Since GetValue<> is an extension method.

Posted by Community Admin on 11-Jan-2012 00:00

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

Posted by Community Admin on 11-Jan-2012 00:00

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

Posted by Community Admin on 13-Jan-2012 00:00

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

Posted by Community Admin on 11-Apr-2012 00:00

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


Posted by Community Admin on 11-Apr-2012 00:00

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


This thread is closed