Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with multile SPCascadedropdowns execution order #85

Open
benbonus2021 opened this issue May 13, 2021 · 2 comments
Open

Issue with multile SPCascadedropdowns execution order #85

benbonus2021 opened this issue May 13, 2021 · 2 comments

Comments

@benbonus2021
Copy link

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
  });

});



@sympmarc
Copy link
Owner

sympmarc commented Jun 29, 2021

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

@benbonus2021
Copy link
Author

Hi Marc,

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

regards

Benjamin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants