Hi All,
I have a requirement using REST.
I have a list A and the column is company, that is lookup column for list company.The data is in Title column of Comapny list.
How to bind company to a dropdown using REST from list A.
Help is needed!
Thanks!
Please see the below example to get lookup from the list.
function gettingInvRole(){
var body = JSON.stringify(body = {
“__metadata”: { “type”: “SP.Data.MyInventoriesRoleListItem” },
});
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists/getbytitle(‘listA’)/items?$select=cmpcompanyLookupId/Id,cmpcompanyLookupId/Title&$expand=cmpcompanyLookupId”
type: “GET”,
headers: {
“X-RequestDigest”: $(“#__REQUESTDIGEST”).val(),
“accept”: “application/json;odata=verbose”,
“content-type”: “application/json;odata=verbose”,
},
success: function (data) {
var i = data.d.results;
console.log(JSON.stringify(data.d.results));
$.each(i, function (index) {
fillingInvRole.push({id:i[index].cmpcompanyLookupId.Id,name: i[index].cmpcompanyLookupId.Title});
});
console.log(“fillingInvRole”+JSON.stringify(fillingInvRole));
for(var j=0;j<fillingInvRole.length;j++){
$(“#cmpRole”).append($(‘<option>’, {
value: fillingInvRole[j].id,
text : fillingInvRole[j].name
}));
}
},
error: function (err) {
}
});
}