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...

有帮助吗?

解决方案

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

其他提示

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

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

should be

filter("Email eq '" + userEmail + "'")
许可以下: CC-BY-SA归因
scroll top