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

Forums / Developing with Sitefinity / Accessing value for custom fields applied to pages

Accessing value for custom fields applied to pages

4 posts, 0 answered
  1. Ed
    Ed avatar
    20 posts
    Registered:
    26 Mar 2013
    08 Apr 2015
    Link to this post

    I added a custom field to my pages called "areaOfStudy". When trying to access the "Title" field like this, it works:

    title = page.GetValue<Lstring>("Title");

    But I get this error:

    System.Exception: Wrong custom field 'areaOfStudy' for type 'Telerik.Sitefinity.Pages.Model.PageData' when I try to access 'areaOfStudy' like this:

    areaOfStudy = page.GetValue<Lstring>("areaOfStudy");

    Any ideas? It's odd that it seems to know I am trying to access a custom field, and that it doesn't work when title does, which is not a custom field. Thoughts?

     

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    09 Dec 2016
    13 Apr 2015
    Link to this post
    Hello Ed,

    You should be able to get properly the value of the field using the sample code you have provided.

    Judging by the error message saying Wrong custom field 'areaOfStudy' for type 'Telerik.Sitefinity.Pages.Model.PageData'  it seems that Sitefinity is not able to find a custom field with the name areaOfStudy for pages. Can you please make sure that the name of the custom field which you use in the code sample is correct?

    In addition to this, please check the type of the field and if it is not a short text or a long text field, please make sure that you are properly specifying the type of the field in the GetValue() method.

    Regards,
    Sabrie Nedzhip
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Monika
    Monika avatar
    2 posts
    Registered:
    14 Jun 2012
    02 Nov 2015
    Link to this post
    Can you please share what the solution was here?  I am  having the same issue.  Thank you.
  4. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    09 Dec 2016
    05 Nov 2015
    Link to this post
    Hi Monika,

    Can you please try to get the custom field from the page node and not from the page data and you should not have problems to get the value of the custom field. Here is a sample for your convenience:

    var pageManager = PageManager.GetManager();
    var pageNode = pageManager.GetPageNodes().Where(p => p.Title == "PageTitle").FirstOrDefault();
      
    var customFieldValue = pageNode.GetValue("FieldNameValue");


    Regards,
    Sabrie Nedzhip
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered