Problem Accessing Custom Field Value

Posted by Community Admin on 04-Aug-2018 21:54

Problem Accessing Custom Field Value

All Replies

Posted by Community Admin on 23-May-2011 00:00

I am using an image album to store photos and bio information for some of the professionals in my company. My goal is to write a user control to display these and offer some advanced functionality that I can't get out of just displaying them in a modified image library in SF. I am binding to a repeater right now as I get familiar with utilizing Fluent. Everything works perfect until I try to access the data values in custom fields I have set up. Below is the code I am using...

Me.rptrTest.DataSource = App.WorkWith().Images().Get().ToList().Where(Function(w) w.Status = ContentLifecycleStatus.Live And w.Album.Title.Value = "Investment Management Professionals" And w.GetValue("ProfessionalName").ToString.StartsWith("K"))

rptrTest.DataBind()


The above code is supposed to filter images, based on what will ultimately be a string parameter fed from another control on the page, against a custom field I have added and stored data in called "ProfessionalName". In this case, I have statically plugged in the letter "K". When trying to run this, the error I receive is:

"Object Reference Not Set To An Instance of an Object."

I know for certain that the custom field I am trying to access exists. If I substitute my custom field name with a built-in fieldname like "Title", I can get it to filter and work correctly. Can someone please help me out here? I'm very new to Fluent and I'm not versed well in C#, so please excuse my use of VB.

Thanks much in advance!

Posted by Community Admin on 24-May-2011 00:00

Hi Craig,

1. Could you tell us where "Object Reference Not Set To An Instance of an Object." is thrown. This is a very common error which says that the object "x" is null

2. If you call Get() before you try to get the item by custom field are there any results?

I suppose that

App.WorkWith().Images().Get().ToList().Where(Function(w) w.Status = ContentLifecycleStatus.Live And w.Album.Title.Value = "Investment Management Professionals"

does not return an item and when you call w.GetValue("ProfessionalName") there is no object "w" that you can query.

Greetings,
Ivan Dimitrov
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 24-May-2011 00:00

Hi Ivan,

It is thrown on that very line. I do get the results I expect if I shave the line back to either of the following and omit "And w.GetValue("ProfessionalName").ToString.StartsWith("K"))":

App.WorkWith().Images().Get().ToList().Where(Function(w) w.Status = ContentLifecycleStatus.Live '//returns all live images as expected
 
App.WorkWith().Images().Get().ToList().Where(Function(w) w.Status = ContentLifecycleStatus.Live And w.Album.Title.Value = "Investment Management Professionals" '//returns all live images in my Investment Management Professionals album as expected

If I add the omitted line back in and change the field name in the "w.GetValue" parameter to a built-in field such as "Title", it works fine. It appears to only fail with custom defined fields.

Posted by Community Admin on 24-May-2011 00:00

Here is a screenshot...

Posted by Community Admin on 24-May-2011 00:00

I've attached a screenshot showing my custom fields. If I plug any of those field names in to the .GetValue(x), I get the error. If I plug any of the default fields in as shown in the bottom of the screenshot, it works just fine.

Posted by Community Admin on 31-May-2011 00:00

Hello Craig ,

I am not able to replicate this issue locally unless this is an issue with the way that the fluent api works in VB( we have some issues with VB way).

I attached a short video with my test.

Greetings,
Ivan Dimitrov
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 07-Jun-2011 00:00

Ivan,

I've redone everything in C# (see code below)  and get a "System.NullReferenceException: Object reference not set to an instance of an object".

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity;
 
 
 
 
public partial class custom_Professionals : System.Web.UI.UserControl
    protected void Page_Load(object sender, EventArgs e)
    
 
        var imgs = App.WorkWith().Images().Where(i => i.Status == ContentLifecycleStatus.Live && i.GetValue<string>("ProfessionalNickName").StartsWith("K")).Get().ToList();
                    rptrTest.DataSource = imgs;
        rptrTest.DataBind();
 
 
         
    


Posted by Community Admin on 09-Jun-2011 00:00

Hello Craig ,

I am sorry, but I am not able to replicate this issue. If you use an older version, please upgrade to the latest one. You can also give a try with a new project to see whether the same issue will occur. You can install it through the project manager for a seconds. You can also open a support request and send some sample project where we can see how you add the custom field.

Greetings,
Ivan Dimitrov
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 14-Jan-2014 00:00

Hi,

I was also having the same problem, I got a solution for this in another forum post Link to post

The solution is, we can get the value like in given manner:
var imageOrder = Telerik.Sitefinity.Model.DataExtensions.GetValue(image, "ImageOrder");

Thanks

Posted by Community Admin on 14-Jan-2014 00:00

Hi Amit,

Thank you for sharing this with the community.

Regards,
Strahil Strahilov
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 Public Issue Tracking system and vote to affect the priority of the items

This thread is closed