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:
-
Loading my [custom] NewForm will deliver the result I wish for.
Customer Names
are filtered based on selectedRegion
,Product Numbers
are filtered based on selectedCustomer Name
andPrevious Order
numbers are filtered based onCustomer Name
AND selectedProduct Number
. -
If I keep the
Region
andCustomer Name
and change theProduct Number
then thePrevious Order
filter list gets populated correctly and works as intended. -
However, once I start changing any of the other values (
Customer Name
orRegion
[incl. the automatically following downstream cascade]) it does not filter as intended. It seems that script keeps using the sameCustomer 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