Getting Custom Fields from Events
We added a custom field to the events form when creating it. The field is a boolean value.
How can we get it programmatically?
Oscar,
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();
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
Just make sure you include this namespace:
using Telerik.Sitefinity.Model;
Since GetValue<> is an extension method.
Hello Dustin,
Take a look at this forum thread. I believe you might find it useful.
All the best,
Jen Peleva
the Telerik team
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"
);
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
Hi,
Hi,