SPCascadeDropdowns : Cant pass selected value to subsequent dropdown

Apr 5, 2011 at 4:42 PM

Hello,

I'm having trouble using multiple dropdowns :

In a first SPCascadeDropDowns, i use this code :

var company;
$().SPServices.SPCascadeDropdowns({
            relationshipList: "{COMPANY LIST ID}",
            relationshipListParentColumn: "Company",
            relationshipListChildColumn: "LinkTitle",
            parentColumn: "Company",
            childColumn: "Activity",
            completefunc: function () { company = $("select[title$='Company']").find("option:selected").text(); },
            debug: true
        });

Then I add a second SPCascadeDropDowns :

$().SPServices.SPCascadeDropdowns({
            relationshipList: "{ACTIVITY LIST-ID}",
            relationshipListParentColumn: "Activity",
            relationshipListChildColumn: "LinkTitle",
            parentColumn: "Activity",
            childColumn: "Activity check",
            CAMLQuery: "<Eq><FieldRef Name='Company' /><Value Type='Lookup'>" + company + "</Value></Eq>",
 promptText: "Choose {0}...", completefunc: function () { alert(company); }, debug: true });

Problem is, the CAML Query never use the company variable, although the alert shows me that the value is correctly retrieved.

Moreover, if I hard code the query with a specfic company name, like this :

CAMLQuery: "<Eq><FieldRef Name='Company' /><Value Type='Lookup'>CompanyName</Value></Eq>",

It works perfectly !

I hope someone can help me on this strange behavior...

Raphael

Coordinator
Apr 5, 2011 at 7:45 PM

Raphael:

A couple of questions:
* What type of column is LinkTitle?
* What happens if you don't pass anything for CAMLQuery?

M.

Apr 5, 2011 at 9:17 PM

Hi Marc,

* In each Parentlist, LinkTitle is the default text string, which is linked to the element menu in list view (with edit, delete, etc). I have replaced it by "Title" but it does not change anything.

* if I dont pass the query, it works but I get some duplicates in the results.

 

To be more precise, Here are some details on the form I use :

A first dropdownlist, a lookup one, is filled with the companies.

A second one is filled with activities corresponding to the company selected.

Then a third one is filled according to the activity, and I want to filter it more by using the company value.

 

Thanks for your help :)

Coordinator
Apr 5, 2011 at 9:27 PM

Ok, I think you're trying to use the function in a different way than intended. Companies -> Activities sounds like a correct use. The third column thing you are trying to do is not.

The call to SPCascadeDropdowns happens when the page loads, and not subsequently. So the value you provide for CAMLquery is only going to be applied once based on the value on that first call.

Make any sense?

M.

Apr 6, 2011 at 8:38 AM
Edited Apr 6, 2011 at 8:38 AM

OK, I was suspecting this...

I am new to jquery and did not know the way it works.

In fact what I want to achieve is similar to this : SPCascadeDropdowns with multiple parent columns

So I suppose a better approach will be to create my own jquery with the GetListItems function ?

Thanks again :)

Raphaël

Apr 6, 2011 at 9:27 AM

Duh, I'm trying the simplest GetListItems call from your documentation, and the alert returns me "undefined".

$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "{List GUID}",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
    alert(xData.responseXML.xml);
      $(xData.responseXML).find("[nodeName=z:row]").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
        $("#tasksUL").append(liHtml);
      });
    }
  });
});

I use the GUID of the list, is this correct ?

What am I missing here ??

Raphael

Apr 6, 2011 at 11:15 AM

Raphael,

     If you are using the latest jQuery, you have to enclose the z:row option in single quotes. Another thing to test would be to alert the responseText in lieu of responseXML.xml so you would have alert(xData.responseText);

That will give you what is being returned from your query.

Apr 6, 2011 at 11:49 AM

spevilgenius,

Thanks a lot ! It works now !

Now I hope I will be able to do what I wanted to do in the first place...

Coordinator
Apr 6, 2011 at 12:17 PM

Just a note:

alert(xData.responseXML.xml);

and

alert(xData.responseText);

have the same net effect.

M.

Apr 6, 2011 at 12:41 PM

Marc, maybe my experience is different, but I have sometimes not been able to alert responseXML.xml because there was an error of some form. responseText worked for me when responseXML.xml did not. Maybe just me!!

Coordinator
Apr 6, 2011 at 12:42 PM

I'd be interested to see exanmples of this, if only for my own edification!

M.

Apr 7, 2011 at 7:34 AM

Well, here is one example :

$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "{GUID}",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
    alert(xData.responseXML.xml); // returns "undefined"
    alert(xData.responseText); // returns xml data
         $(xData.responseXML).find("[nodeName='z:row']").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
        $("#test").append(liHtml);
      });
    }
  });

On my form, this simple code works like a charm, except for the first alert

alert(xData.responseXML.xml);

I would gladly add some details if you need to. :)

Raphael

Coordinator
Apr 7, 2011 at 1:39 PM

Weird. I used

alert(xData.responseXML.xml);

for a really long time and never had issues. Then I learned that I could use

alert(xData.responseText);

and I started using it, but I flip back and forth and I've always found them to be interchangeable.

I guess

alert(xData.responseText);

is the better way to go!

M.

Apr 20, 2011 at 10:59 AM
CaptainCaverne wrote:

OK, I was suspecting this...

I am new to jquery and did not know the way it works.

In fact what I want to achieve is similar to this : SPCascadeDropdowns with multiple parent columns

So I suppose a better approach will be to create my own jquery with the GetListItems function ?

Thanks again :)

Raphaël

 

I would like to see how you implemented this as this is exactly the kind of thing I am trying to achieve as well.