Hi,
This is a question about rest and sharepoint.
I am fetching the items of a list and one of its column is a people column called SalesManager.
When I run console.log I see the name as two properties:
SalesManager {
FirstName: John
LastName: Doe
}
I know that expanding the SalesManager I can get the First and Lastname like this:
let select: string =
"SalesManager/FirstName, SalesManager/LastName";
const items = await sp.web.lists
.getByTitle("AgreementDatabase")
.items.select(select)
.expand("SalesManager,TaxCatchAll")
.get();
With that expansion I can set the SalesManager name in the state in this way:
items.forEach(item => {
Agreements.push({
SalesManager:
item.SalesManager.FirstName + " " + item.SalesManager.LastName
});
});
and it renders on the page like John Doe. No problems there.
What I want to do now is filter the result based on the SalesManager’s name (John Doe)
So I did this:
First I fetched the current logged user name:
let currentUser = '';
sp.web.currentUser.get().then(result => {
currentUser = result.Title;
});
currentUser has now John Doe.
in the query I tried do this:
let select: string =
"SalesManager/FirstName, SalesManager/LastName";
const items = await sp.web.lists
.getByTitle("AgreementDatabase")
.items.select(select)
.filter(`'SalesManager/FirstName' + ' ' + 'SalesManager/LastName eq '${currentUser}'`)
.expand("SalesManager,TaxCatchAll")
.get();
I tried to put together the First and Lastname and then compare it with the currentUser. Obviously it didn’t work. But I think it should be a way to do it.
Do you now how it is done?
I just noted that I wrote the same post twice but I can’t delete them. Sorry for this!!
Best regards
Americo