sympmarc / SPServices

SPServices is a jQuery library which abstracts SharePoint's Web Services and makes them easier to use. It also includes functions which use the various Web Service operations to provide more useful (and cool) capabilities. It works entirely client side and requires no server install.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with multile SPCascadedropdowns execution order

benbonus2021 opened this issue · comments

I have four lists, Regions, Customers, Products and Orders. The Orders list is where all the roads meet.

An order includes a Region field as lookup into the Regions list, a Customer Name field which is a lookup into the Customers list and a Product Number field which is a lookup into the Products list. In addition it inludes an Current Order field and a Previous Order field which is a lookup into this Current Order field.

Each Customer is assigned to a region (lookup field into Regions). Each customer can have several product numbers and each product number might be assigned to (bought by) different customers.

Now my aim is:
to ensure that my Previous Order numbers displayed are really restricted to the same customer and the same product number. So I would like to filter the Previous Order entries based on Customer Name and Product Number.

My according JS code is below. I use jQuery 3.6.0 and SPServices 2014.02.

Now here is my problem:

  1. Loading my [custom] NewForm will deliver the result I wish for. Customer Names are filtered based on selected Region, Product Numbers are filtered based on selected Customer Name and Previous Order numbers are filtered based on Customer Name AND selected Product Number.

  2. If I keep the Region and Customer Name and change the Product Number then the Previous Order filter list gets populated correctly and works as intended.

  3. However, once I start changing any of the other values (Customer Name or Region [incl. the automatically following downstream cascade]) it does not filter as intended. It seems that script keeps using the same Customer Name for filtering - which breaks the code/filter.

My question is:
Can anybody tell how I need to adjust my code to fix the problem and achieve the result described above?

var myJQ = jQuery.noConflict(true);
var sCamlQuery = "";

myJQ(document).ready(function() {
    myJQ().SPServices.SPCascadeDropdowns({

    relationshipList: "Customers",
    relationshipListParentColumn: "Region",
    relationshipListChildColumn: "Customer_x0020_Name",
    parentColumn: "Order Region",
    childColumn: "Customer Name",
    completefunc: function() {
		alert('Filter customer based on region');
    },
    
    debug: true
  });
  
   myJQ().SPServices.SPCascadeDropdowns({
    relationshipList: "Orders",
    relationshipListParentColumn: "Customer_x0020_Name",
    relationshipListChildColumn: "Product_x0020_Number",
    parentColumn: "Customer Name",
    childColumn: "Product Number",
    completefunc: function() {
          sCamlQuery = "<Eq><FieldRef Name='Customer_x0020_Name'/><Value Type='Text'>" + $("input[Title='Customer Name'], select[Title='Customer Name Required Field']").find("option:selected").text() + "</Value></Eq>";
    },
    debug: true
  });
   
  myJQ().SPServices.SPCascadeDropdowns({
    relationshipList: "Orders",
    relationshipListParentColumn: "Product_x0020_Number",
    relationshipListChildColumn: "Current_x0020_Order_x0020_no",
    parentColumn: "Product Number",
    childColumn: "Previous Order",
    CAMLQuery: sCamlQuery,

    completefunc: function() {
    	var value = $("input[Title='Customer Name'], select[Title='Customer Name Required Field']").find("option:selected").text();
        alert('Filter Previous Order based on product number');		
        alert('Field value is ' + value + '.');
        alert('sCamlQuery value is ' + sCamlQuery + '.');
    },
    debug: true
  });

});



Sorry I didn't see your question sooner. You may well have already solved this.

The way you have your code set up, the relationships are:
Customer -> Region, CustomerName -> ProductNumber, and ProductNumber -> CurrentOrderNo
But since the latter two are both coming from Orders, there is undoubtedly not a hierarchical relationship to those two.

Instead, I would expect something based on the relationships in the three lists: Regions, Customers, Products

Hi Marc,

no I haven't. So probably I need to rethink the relationship. Thanks.

regards

Benjamin