0

I use SharePointPlus and I'm trying to use localStorage variable in the WHERE clause. Below my code:

$SP().list('Pracownicy').get({
  fields:"SID,Dost_x0119_py,Dost_x0119_py_Zam,Dzia_x0142_,Rola",
  where:"SID = localStorage.getItem('sid')"
  ....

This variable is a string. Unfortunately it doesn't work. Is it possible to use such variable there? Thanks in advance.

2 Answers 2

1

If it's a string you must also include quotes :

$SP().list('Pracownicy').get({
  fields:"SID,Dost_x0119_py,Dost_x0119_py_Zam,Dzia_x0142_,Rola",
  where:'SID = "' + localStorage.getItem('sid') + '"' 
  ....

It would also be better to test the return of your local storage before using it, like :

var sid = localStorage.getItem('sid');
if (!sid) alert("error") 
else {
  $SP().list('Pracownicy').get({
  fields:"SID,Dost_x0119_py,Dost_x0119_py_Zam,Dzia_x0142_,Rola",
  where:'SID = "' + sid + '"' 
  ....
0
0

I don't know about SharePoint Plus, but I think the right way to get the local storage and add to your where clausule is:

"SID = " + localStorage.getItem('sid'),

and remove comma(,) if where is the last property.

The way you're doing:

"SID = localStorage.getItem('sid')"

are making the code understand that localStorage.getItem('sid') is a String instead of variable;

1
  • It doesn't work. Unfortunately I suppose it must be specific string. Commented Mar 13, 2018 at 14:58

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.