JSOM Querying lists with lookup objects. RRS feed

  • Question

  • So I created a list, and I can happily use the CEWP to insert Javascript to query the list (with CAML) and return the field values from the list.

    Next, I altered the list so thast 1 column is a lookup column.
    Specificaly, it's a lookup to select a page from the same site.
    Sharepoint did not offer me the Page Name to select from, so I am using 'Title'.
    Title is now stored in my list as 'Page_Title'.

    Now, going back to my Javascript.
    When I get to the field 'Page_Title', instead of a value, I am getting an object.

    Ok, so this makes sense, I understand 'why' I am getting an object.
    However, I am struggling on how to handle the object to uncover it's properties.

    My best hope so far has only produced error :

    Any pointers ?

    Sunday, November 16, 2014 10:20 AM


All replies

    • Marked as answer by SimonB2013 Monday, November 17, 2014 9:48 AM
    Monday, November 17, 2014 2:24 AM
  • If your list object is listObject as below and your lookup column is 'Page_Title', then you can get the value as below - 
    var lookupTitleField = listObject.get_item("Page_Title");
    var lookupTitleValue = lookupTitleField.get_lookupValue();

    Srini Sistla Twitter: @srinisistla Blog: http://blog.srinisistla.com

    • Marked as answer by star.wars Tuesday, December 9, 2014 8:16 AM
    Monday, November 17, 2014 2:44 AM
  • That's a great reference, thankyou, it works !

    I think I am going to have to go away and think about how to impliment this in my final script properly.
    From what I see, if you have several lookup columns, the code could get messy making all these extra calls.

    But this is the door open, so much appreciated !

    Monday, November 17, 2014 9:48 AM
  • Thank you ...
    This works good.
    Monday, November 17, 2014 9:48 AM