0

I have to read values from two lookup fields. I am getting values with one of them but for the other it shows undefined.

$.ajax({
        url:_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Certifications')/Items?$filter="+filterById+"&$select=Title,Subsystem/ID,Subsystem/Title,Belongs_x0020_To/Title,Belongs_x0020_To/ID&$expand=Subsystem,Belongs_x0020_To",
        type: "GET",     
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
        //alert(data.d.results[0].Belongs_x0020_To);
        //alert(data.d.results[0].Belongs_x0020_To);
        //alert(data.d.results[0].Title);           
        }
6
  • Which one is undefined Belongs_x0020_To or others? Nov 19, 2015 at 9:37
  • Pro tip, do a console.dir(data) in the success method to get the returned object printed to the console in for example Chrome. Then you can see how the object is composed Nov 19, 2015 at 9:40
  • data.d.results[0].Belongs_x0020_To.Title and data.d.results[0].Belongs_x0020_To.ID is undefined
    – KumarV
    Nov 19, 2015 at 9:42
  • 1
    I guess your $filter="+filterById+" is returning some null Belongs_x0020_To. Can you check it manually in the list @vikashkumar Nov 19, 2015 at 10:03
  • If it is null, i thought it should show null value bt it showed undefined. When I added some values to those columns then it worked.
    – KumarV
    Nov 19, 2015 at 10:32

2 Answers 2

1

For checking your internal names:

Goto the List\Library settings page listing all fields (also works on ContentType definition)

and run the F12 code:

[].slice.call(document.getElementsByTagName('a'))
.forEach(function(a){
  if(a.href.indexOf('Field=')>0) 
      console.log(a.innerHTML,'=',a.href.split('Field=')[1].split('&Fid=')[0]);
 })

I have it under a BookmarkLet link, ready to use in any site I browse to.

A Standard TASKS list logs:

iFIELDS

0

I guess, that you just have the wrong column name (the naming in SharePint sometimes aapears a little chaotic). The best way is to give out the URL (via console.log() or alert() ) and than just display the result in the browser. There you can see how the fields are named.

If this won't help: If you want to access single fields of a lookup content type it sometimes just working if you integrate them in the column.

  • Go to List => List Settings => YourContentTypeColumn
  • Scroll down to "Add a column to show each of these additional fields"
  • Check the columns you you need to access

I have no idea why this sometimes is needed (and sometimes not).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.