I am trying to query a list in sharepoint using rest and one of the columns is a lookup column that get the data from another columns. This column can or can not have data is not mandatory. The problem I have is that when I query the list rest is dropping an undefined error since not all the row in the list has that column with data. I am wondering how can I read the data from the list so rest skip the undefined value and keep reading the rest of the list?
This is how I am making the request:
private select = "FrameworkAgreement/Title";
private listTitle = "Agreement Database";
private expandParam = "FrameworkAgreement";
public async getListItems(): Promise<IList[]> {
let Agreements: IList[] = [];
const items = await sp.web.lists
.getByTitle(this.listTitle)
.items.select(this.select)
.expand(this.expandParam)
.get();
items.forEach(item => {
Agreements.push({
FrameworkAgreement: item.FrameworkAgreement.Title, // This get undefined if no data is in the column
});
});
return new Promise<IList[]>(async resolve => {
resolve(Agreements);
});
}
Whe rest reach the line FrameworkAgreement: item.FrameworkAgreement.Title It can happens that just that row doesn’t have any value.
How can I check som kind of ternary operator to check if there is something in the title property?
I have tried like this, but rest still saying that the Title property, the one inside the parenthesis) is undefined so it can’t check it:
FrameworkAgreement: (item.FrameworkAgreement.Title === "undefined") ? "" : item.FrameworkAgreement.Title
Best regards Americo