I have a custom button when on click I book a desk. On click on the button I want to check if current user has a desk booked (day is a Look up field in dd/MM/yyyy' format). to denote the booking user is Assigned the desk (i.e. Asssigned to field).
ChartGP has generated below. but its not working
const today = new Date().toLocaleDateString('en-GB'); // format date as dd/MM/yyyy
const currentUserID = _spPageContextInfo.userId; // get current user email
pnp.sp.web.lists.getByTitle('Desks').items
.select('AssignedToID', 'Day/Day', 'Desk')
.expand('AssignedTo', 'Day')
.filter(`AssignedToID '${currentUserID}' and Day/Day eq '${today}'`)
.get()
.then(items => {
if (items.length > 0) {
// user has a desk booked for today
console.log(`User ${currentUserID} has desk ${items[0].Desk} booked for today.`);
alert(`User ${currentUserEmail} has desk ${items[0].Desk} booked for today.`);
} else {
// user does not have a desk booked for today
console.log(`User ${currentUserID} does not have a desk booked for today.`);
alert(`User ${currentUserEmail} does not have a desk booked for today.`);
}
})
.catch(console.log);
Any ideas?