Issues with creating multiple Cascading rules tied to same lookup list

Forums Cascading dropdowns Issues with creating multiple Cascading rules tied to same lookup list

This topic contains 12 replies, has 3 voices, and was last updated by  Alexander Bautz 1 year, 6 months ago.

  • Author
    Posts
  • #9886

    Jon Whisman
    Participant

    Hi,

    I have a screenshot attached that I hope helps.

    I’m able to get Cascading Dropdowns working fine with one branch that looks up one list and fills in the field I need, but The solution breaks when I try to make multiple branches (rules) within Cascading Dropdowns that all call the same lookup list. I have 4 fields on my primary list, each of I’d like to fill with values from my lookup list. Here’s the example:

    Current List fields (single line of text) that I want to populate with dropdown options from the lookup:

    Primary Exception Code
    Secondary Exception Code
    Third Exception Code
    Fourth Exception Code

    The user has the option to pick dropdown values from each of the four fields. The four fields all call the same lookup list, but populate different values in the current list.

  • #9919

    AdamP
    Participant

    I think you’re just configuring this incorrectly – it looks like you’re targeting the same field (Channel) in both config sections, which would be impossible, and also using the same list of options for both primary and secondary exception code fields – possible but doesn’t sound likely. Is it really cascading dropdowns that you want?

    To get a four level cascade, you simply list the four fields in the “lookup” list, and then the four fields in the form you want to populate – the “current” list.
    From Alexander’s post;

    lookupListFields: The FieldInternalNames of the fields in the above list.
    thisListFields: The FieldInternalNames of the fields to convert to dropdowns.

    And importantly:

    The length of the arrays “lookupListFields” and “thisListFields” must be the same.

    ie just pair up the from and to fields, and list them in the right order.

    So in your lookup list field you’d have eg Column1,Column2,Column3,Column4
    And in the current list field eg Primary,Secondary,Third,Fourth

    See the original post

  • #9949

    Alexander Bautz
    Keymaster

    Hi,
    I did a quick check to see if I could set up a scenario like your image in the first post. I had no problem setting up this test:

    Attachments:
  • #9955

    AdamP
    Participant

    Hi Alexander

    I think Jon’s scenario in the image and your example are slightly different in that Jon is targeting the same field (Channel) on the form twice – as far as I can see that’s an impossibility? Your example targets four completely separate fields – two pairs which cascade nicely.
    Jon’s scenario translated into your example would equate to;
    Casc1,Casc2
    Casc1,Casc4
    in the config for the current list fields. Am I missing something?

  • #9957

    Alexander Bautz
    Keymaster

    You are correct – this is not possible and explains the error.

    Alexander

  • #9973

    Jon Whisman
    Participant

    Thank you, both. I think what I need is SPJS-lookup. The user will pick the “channel” option”, and then I will set drop down options within 8 different fields. These options could be different based on the “Channel” they choose. Is this something that SPJS-lookup can do? From what I’m reading, it seems like it can….

  • #10030

    AdamP
    Participant

    Hi Jon

    This isn’t something I’ve done and looks pretty complex (to me) to achieve.
    If I understand you correctly, it sounds like you want to do something similar to the example in this post, but with eight sub-menus filtered off the first selection rather than just one;
    Combining SPJS-Lookup with Cascading Dropdowns

    Adam

  • #10046

    Jon Whisman
    Participant

    Yes, that’s correct. User picks 1 option, which triggers eight sub-menus filtered
    off the first selection. The eight sub-menus all have codes like “reason code 1, “reason code 2″…but vary based on that first selection.

  • #10074

    Alexander Bautz
    Keymaster

    Here is a possible solution (if I understand you correctly).
    1:
    Add a list named “LookupList_SPJSLookupOneToMany” with two columns “Level1” and “Level2”, and fill it like the attachment shows.

    2:
    Add four field to your main list: “SPJSLookupParent”, “SPJSLookupChild1”, “SPJSLookupChild2” and “SPJSLookupChild1”.

    3:
    Add this to the Custom JS:

    spjs.lookup.init({
    	"fieldToConvertToDropdown":["SPJSLookupParent"],	
    	"listName":"LookupList_SPJSLookupOneToMany",
    	"listBaseUrl":"/DFFS",
    	"optTextFieldInternalName":"Level1",
    	"sortFieldName":"Level1",
    	"filterObj":{
    		"on":false,
    		"folder":"", // Leave empty to search in all folders
    		"CAML":null, // If used, the rest of the filterObj settings are disregarded
    		"fin":"Completed",
    		"isLookup":false,
    		"operator":"Neq",
    		"filterVal":"1"
    	},
    	"dropDownDefaultvalue":"...",
    	"addYouOwnValue":{
    		"on":false,
    		"linkText":"Write your own value"
    	},
    	"addToExternalList":{
    		"on":false,
    		"customFunction":null, // Function name as a string. If a function name is supplied, this will be used in stead of the default function. The function will be passed the argument object as a parameter.
    		"linkText":"Add new item",
    		"saveNewItemText":"Save new item"
    	},
    	"debug":false
    });
    
    $("#SPJSLookupParent_spjs_lookup").change(function(){
    	var val = $(this).find("option:selected").text();
    	// Delete current instances of child selects
    	spjs.lookup.kill("SPJSLookupChild1");
    	spjs.lookup.kill("SPJSLookupChild2");
    	spjs.lookup.kill("SPJSLookupChild3");
    	// Add new
    	spjs.lookup.init({
    		"fieldToConvertToDropdown":["SPJSLookupChild1","SPJSLookupChild2","SPJSLookupChild3"],	
    		"listName":"LookupList_SPJSLookupOneToMany",
    		"listBaseUrl":"/DFFS",
    		"optTextFieldInternalName":"Level2",
    		"sortFieldName":"Level2",
    		"filterObj":{
    			"on":true,
    			"folder":"", // Leave empty to search in all folders
    			"CAML":null, // If used, the rest of the filterObj settings are disregarded
    			"fin":"Level1",
    			"isLookup":false,
    			"operator":"Eq",
    			"filterVal":val
    		},
    		"dropDownDefaultvalue":"...",
    		"addYouOwnValue":{
    			"on":false,
    			"linkText":"Write your own value"
    		},
    		"addToExternalList":{
    			"on":false,
    			"customFunction":null, // Function name as a string. If a function name is supplied, this will be used in stead of the default function. The function will be passed the argument object as a parameter.
    			"linkText":"Add new item",
    			"saveNewItemText":"Save new item"
    		},
    		"debug":false
    	});
    });

    If you change the name of any of the fields, adapt the code by changing the names.

    Hope this helps,
    Alexander

  • #10304

    Jon Whisman
    Participant

    Sorry for my delay in responding. This solution worked amazingly well! One question though: At the moment, if I open an existing item in EditForm, the fields to convert to dropdown are still single line of text until I toggle the parent field, forcing a change event. After this, I see the dropdowns and the options. How do I get the code fire on form load, rendering the single lines as dropdowns when EditForm opens, so that a user doesn’t have to do that?

  • #10356

    Alexander Bautz
    Keymaster

    I’m glad it worked. Try changing the last line in my code example from this:

    });

    to this:

    }).trigger("change");

    Alexander

  • #10375

    Jon Whisman
    Participant

    PERFECT! Thank you again. What is the JS code for a hug / high five to you?! Cheers!

  • #10399

    Alexander Bautz
    Keymaster

    Thanks, I’m glad it worked out.

    Alexander

You must be logged in to reply to this topic.