Pregunta

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

¿Fue útil?

Solución

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

Otros consejos

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

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

should be

filter("Email eq '" + userEmail + "'")
Licenciado bajo: CC-BY-SA con atribución
scroll top