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.
    – Marek Lopi
    Mar 13, 2018 at 14:58

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .