how to pass $().SPServices.SPGetCurrentSite(); has a prameter in CAMLQuery

Mar 21, 2011 at 6:20 AM

Hi All,

     As you can see below i'm trying to build up a menu using my  favorite SPServices below.
So i want to get the current site the user is on and then pass it to my CAMlQuery below
But it seems the the var doesn't get to the CAMlQuery.

I know i'm missing something e.g how to use $().SPServices inside another $().SPServices

Any ideas and thanks in Advance

var thisSite = $().SPServices.SPGetCurrentSite();

//var sitename = "RetailBiz"; 
   $().SPServices({
   webURL: "/sites/MySite/",
   operation: "GetListItems",
    async: false,
    listName: "Menu",
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='SiteName' Ascending='True'/><Value  Type='Text'>" + thisSite + "</Value></Eq></Where></Query>",
    //CAMLQuery: "",
    CAMLViewFields: "",
    //CAMLViewFields: "",
Coordinator
Mar 21, 2011 at 11:23 AM
Edited Mar 21, 2011 at 11:23 AM

I can't spot anything obvious. What results are you seeing? Does the call work without the CAMLQuery value? What do you see if you alert thisSite?

M.

Mar 21, 2011 at 10:33 PM

Marc...
      Yes it does work if i hard code the value e.g var sitename = "RetailBiz";
If i add an alert just after the

var thisSite = $().SPServices.SPGetCurrentSite();

alert(thisSite); I get the correct value
But when i add it to the CAMLQuery i dont get my filtered list returned.
Hope you get me

Thanks

Coordinator
Mar 22, 2011 at 3:00 AM

What do the values in the SiteName column look like? $().SPServices.SPGetCurrentSite(); is going to return values like the ones shown at the bottom of the doc page:
http://spservices.codeplex.com/wikipage?title=$().SPServices.SPGetCurrentSite

M.

Mar 22, 2011 at 3:33 AM

Thanks Marc I know and  have removed the values i don't need.
So lets say it retruns the below

 http://servername/sitename

I only get the sitename which is good and i have tested this with the alert.

The problem is the value can't get pass the  $().SPServices({}

Chrs

Mar 22, 2011 at 12:33 PM

When you are declaring this variable, is it within the same scope that you are trying to use it?  Just to be clear, you have declared a local variable and it's TTL (time to live) is generalized to the specific function you are using this variable in.  It appears that this may not be the case, but we are only looking at a snippet of the code, so it very well could be a variable scope issue.

Coordinator
Mar 22, 2011 at 1:57 PM

You should be fine on the scoping based on what you show in your initial post. Howver, you could simply change to this to be certain:

   $().SPServices({
   webURL: "/sites/MySite/",
   operation: "GetListItems",
    async: false,
    listName: "Menu",
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='SiteName' Ascending='True'/><Value  Type='Text'>" + $().SPServices.SPGetCurrentSite() + "</Value></Eq></Where></Query>",
    //CAMLQuery: "",
    CAMLViewFields: "",
    //CAMLViewFields: "",

I think the issue is something else, though, and I'm guessing it's that the value of the SiteName column simply doesn't match the value returned by $().SPServices.SPGetCurrentSite().

A little debugging!

M.

Mar 22, 2011 at 10:56 PM

Marc lets say i have
http://servername/sites/sitecoll/sitename

using

  alert($().SPServices.SPGetCurrentSite().replace("http://servername/sites/sitecill/", " "));
gives me sitename

and thats what i pass to

 CAMLQuery: "<Query><Where><Eq><FieldRef Name='SiteName' Ascending='True'/><Value  Type='Text'>" + sitename + "</Value></Eq></Where></Query>", but no luck

unforunately i can't just use :
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='SiteName' Ascending='True'/><Value  Type='Text'>" + $().SPServices.SPGetCurrentSite() + "</Value></Eq></Where></Query>",
has the value its passing is "http://servername/sites/sitecoll/sitename"

Sorry for the questions but its the last thing i need to do to make my menu much more generic
Thanks
Mar 22, 2011 at 11:35 PM

Fixed Marc..
I was relying the the value sitename i was getting was trimmed.
Trimmed it and it works lke a charm
**Never give up :)

Coordinator
Mar 23, 2011 at 12:56 PM

Glad you got it working!

M.