SPCascadeDropdowns CAML Query Evaluation

Feb 23, 2015 at 10:06 PM
Hello,

I have a bit of a unique scenario for using SPCascadeDropdowns and am hoping there may be a solution to my issue without needing to write my own filtering. Basically, I have an 'Inventory' list and a 'Inventory Transactions' list.

The 'Inventory' list has data in it like the below:

Location - Media - Length
Loc1 - Media1 - 2
Loc1 - Media1 - 3
Loc1 - Media1 - 4
Loc1 - Media2 - 2
Loc1 - Media2 - 3
Loc1 - Media2 - 4
Loc2 - Media1 - 3
Etc...

The 'Inventory Transactions' lists uses these 3 fields from the 'Inventory' list as lookup columns.

So, in the 'Inventory Transactions' list, I bind a change event to the 'Location' field which runs SPCascadeDropdowns to filter the 'Media' lookup field on 'Location' and 'Media', after which I have a completefunc that removes the duplicates.

I then bind a change event to the 'Media' field that filters 'Length' on 'Media' and 'Length', and since I have the same Media and length values for multiple locations, I also hit it with a CAML query to filter using the currently selected location, so only the 'Media' and 'Lengths' that exist for that location are populated into the dropdown. I also have a completefunc on this one to round the numbers to a single decimal.

This all works just fine on the first try, but subsequent selections in the same session do not seem to evaluate the CAML query again, nor is it running the completefunc again.

Is this the case by design? If so, is there a way to force evaluation of the CAML query and run the completefunc each time SPCascadeDropdowns is called?

Here is my code:
    $(locationFld).bind("change input propertychange", function() {
      $().SPServices.SPCascadeDropdowns({
        relationshipList: "Inventory",
        relationshipListParentColumn: "Location",
        relationshipListChildColumn: "Media",
        parentColumn: "SiteCode",
        childColumn: "Media"
        completefunc: function() {
            RemoveDropdownDuplicates(mediaFld);
        }
      });
      $(mediaFld).trigger("change");
    })

    $(mediaFld).bind("change input propertychange", function() {
      if (!firstRun) {
        var locFldVal = $("option:selected", locationFld).text();
        var camlQ = "<Eq><FieldRef Name='Location'/><Value Type='Text'>" + locFldVal + "</Value></Eq>";
        $().SPServices.SPCascadeDropdowns({
          relationshipList: "Inventory",
          relationshipListParentColumn: "Media",
          relationshipListChildColumn: "Length",
          CAMLQuery: camlQ,
          parentColumn: "Media",
          childColumn: "Length",
          completefunc: function() {
            console.log("completed");
            $("option", lengthFld).each(function () {
              if (this.text.indexOf(".5") < 0) {
                this.text = (Math.round(this.text));
              } else {
                this.text = Math.round(this.text * 10) / 10;
              }
            });
          }
        });
      }
    })
    
Thanks!
Feb 23, 2015 at 11:08 PM
I should have tested this prior -- I can get the functionality I want from the SPFilterDropdown function. Sorry for the noise...

New code:
    $(locationFld).bind("change", function() {
      var locFldVal = $("option:selected", locationFld).text();
      $().SPServices.SPFilterDropdown({
        relationshipList: "Inventory",
        relationshipListColumn:"Media",
        columnName:"Media",
        CAMLQuery:"<Eq><FieldRef Name='Location'/><Value Type='Text'>" + locFldVal + "</Value></Eq>",
        completefunc: function() {
          // console.log("completefunc");
          RemoveDropdownDuplicates(mediaFld);
        },
        debug: true
      })
    })

    $(mediaFld).bind("change", function() {
      var locFldVal = $("option:selected", locationFld).text();
      var medFldVal = $("option:selected", mediaFld).text();

      $().SPServices.SPFilterDropdown({
        relationshipList: "Inventory",
        relationshipListColumn: "Length",
        columnName: "Length",
        CAMLQuery: "<And><Eq><FieldRef Name='Location'/><Value Type='Text'>" + locFldVal + "</Value></Eq><Eq><FieldRef Name='Media' /><Value Type='Text'>" + medFldVal + "</Value></Eq></And>",
        completefunc: function() {
          // console.log("media func running" + medFldVal);
          $("option", lengthFld).each(function () {
            if (this.text.indexOf(".5") < 0) {
              this.text = (Math.round(this.text));
            } else {
              this.text = Math.round(this.text * 10) / 10;
            }
          });
        },
        debug: true
      })
    })