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

Forums / Developing with Sitefinity / Problem Accessing Custom Field Value

Problem Accessing Custom Field Value

10 posts, 0 answered
  1. SVA Webmaster
    SVA Webmaster avatar
    85 posts
    Registered:
    18 Jul 2007
    23 May 2011
    Link to this post
    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!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    24 May 2011
    Link to this post
    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
  3. SVA Webmaster
    SVA Webmaster avatar
    85 posts
    Registered:
    18 Jul 2007
    24 May 2011
    Link to this post
    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.
  4. SVA Webmaster
    SVA Webmaster avatar
    85 posts
    Registered:
    18 Jul 2007
    24 May 2011
    Link to this post
    Here is a screenshot...
  5. SVA Webmaster
    SVA Webmaster avatar
    85 posts
    Registered:
    18 Jul 2007
    24 May 2011
    Link to this post
    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.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    31 May 2011
    Link to this post
    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
  7. SVA Webmaster
    SVA Webmaster avatar
    85 posts
    Registered:
    18 Jul 2007
    07 Jun 2011
    Link to this post
    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();
     
     
             
        }
    }


  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    09 Jun 2011
    Link to this post
    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
  9. Amit
    Amit avatar
    43 posts
    Registered:
    15 Nov 2012
    14 Jan 2014
    Link to this post
    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
  10. Strahil Strahilov
    Strahil Strahilov avatar
    24 posts
    Registered:
    06 Nov 2014
    14 Jan 2014
    Link to this post
    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
10 posts, 0 answered