1

As I am new to Sharepoint framework , I am trying to filter the retrieved list items from sharepoint list. Please find below code:

pnp.sp.web.currentUser.get().then(function(res){  
 
var userEmail = res.Email;
  });
     
pnp.sp.web.lists.getByTitle('EmployeeMaster').items.select("EmployeeID,Title,Designation,Email").filter("Email eq " + userEmail + "'").get().then(function(results){
      
var empID = results[0].EmployeeID;});

Above code is giving me an error of undefined. Please suggest an workaround...

2
  • What is the column type of Email ? Is it a single line of text or you are trying to filter on Email of Person or Group column ? Commented Aug 18, 2020 at 5:59
  • it is Single line of text Commented Aug 18, 2020 at 6:03

2 Answers 2

3

You could check the code for this error(SitePages). enter image description here

If it is caused by this error, you can find the solution here.

https://github.com/SharePoint/PnP-JS-Core/wiki/Using-sp-pnp-js-in-SharePoint-Framework

Updated code:

pnp.sp.web.currentUser.get().then(function(res){  
 
var userEmail = res.Email;
pnp.sp.web.lists.getByTitle('EmployeeMaster').items.select("EmployeeID,Title,Designation,Email").filter("Email eq '" + userEmail + "'").get().then(function(results){
      
var empID = results[0].EmployeeID;});
  });
     

js asynchronous request order solution for your reference:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

6
  • _api/web/lists/getByTitle('EmployeeMaster')/items?...This is the api which I am getting.. Commented Aug 18, 2020 at 5:40
  • Which variable does the error message say is undefined?
    – Amos
    Commented Aug 18, 2020 at 5:43
  • when I pass a static email i.e. filter("Email eq '[email protected]'")....then it works fine but on passing the variable it is not working Commented Aug 18, 2020 at 5:56
  • 1
    Check the update.All are asynchronous requests, the order issue is particularly important.
    – Amos
    Commented Aug 18, 2020 at 6:05
  • Thanks...Now it's working fine Commented Aug 18, 2020 at 6:13
2

It looks like you're missing a single quote in your filter expression.

filter("Email eq " + userEmail + "'")

should be

filter("Email eq '" + userEmail + "'")
1
  • I have tried this as well..it is not working Commented Aug 17, 2020 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.