I want to fetch items of Person or Group type column from another list in React SharePoint but there is a restriction I cannot use it in a single query. So far I have only known using REST. So if anyone has any idea how to use nested calls and filtering the common items between both columns. OR Using another type of query can also be helpful for me.
I am trying to use this way of nested query though and so far it is fetching only from APP_NAME2 but I want common items from both lists:
rows1 and columns1 are the property of DataTable in react-data-table-component.
APP_NAME1 - BID(lookup column in APP_NAME2) and Temperature.
APP_NAME2 - ID, Created By (Field - Author).
private userData = () => {
$.ajax({
url: `${this.props.siteUrl}/_api/Web/Lists/GetByTitle('APP_NAME1')/items?$select=*,BookingID/ID&$expand=BookingID`,
type: "GET",
dataType: "json",
headers: {
accept: "application/json;odata=verbose",
},
success: (resultData) => {
var listdata = {
accounting: [],
};
console.log(resultData.d.results);
$.each(resultData.d.results, (index, value) => {
listdata.accounting.push({
BookingID: value.BookingID.ID,
});
});
console.log(listdata.accounting);
$.ajax({
url: `${this.props.siteUrl}/_api/Web/Lists/GetByTitle('APP_NAME2')/items?$select=Title,Author/ID&$expand=Author&$filter=ID eq + BookingID`,
type: "GET",
dataType: "json",
headers: {
accept: "application/json;odata=verbose",
},
success: (resultData) => {
var listData= {
accounting: [],
};
console.log(resultData.d.results);
$.each(resultData.d.results, (index, value) => {
listData.accounting.push({
Author: value.Title,
BookingID: value.Author.ID,
});
});
console.log(listData.accounting);
this.columns1 = [
{
name: "Employee Name",
selector: "Author",
},
{
name: "ID",
selector: "BookingID",
},
];
this.rows1 = listData.accounting;
this.setState({ healthScreening: listData.accounting }, () => {});
},
error: (jqXR, textStatus, errorThrown) => {
console.log("error");
},
})
},
error: (jqXHR, textStatus, errorThrown) => {
console.log("error");
},
});
}