1

Please excuse me for the vaugness, required due to the type of work.

I have a list that indicates upcoming work on various items. When the work is finished on those items, drawings need updated. As it is, I have the items showing the date that the work is finished and a lookup that lists the various work numbers being performed on that item. The work being performed affects various drawings, so I have another lookup that looks up all the drawings. I want the first lookup for the work numbers to cascade to the drawings lookup, so that when I select the work numbers, only the drawings that are affected will auto populate. I do not have access to InfoPath or SPD (my company restricted that). So, all I can do is put script in a webpart. Any ideas?

I have found script that works when the first lookup is just one item, it will then show only the items that apply in the next lookup. I can't seem to find anything that will let me select multiple items in the first lookup and display all applicable items in the second.

0

Seems you are looking for multi select cascading dropdowns, I found at code at below link, not tried though. But I think this should work with some tweaks.

Ref link - https://social.msdn.microsoft.com/Forums/en-US/8d0ba6f6-8545-425e-8b4c-40e220b64f5a/cascade-dropdown-for-multi-select-lookup-fields?forum=sharepointdevelopment

using // (Newform.aspx, EditForm.aspx, or any other customized form.)
$.fn.SPServices.SPCascadeMultiSelect = function(options) {

    var opt = $.extend({}, {
    relationshipWebURL: "", // [Optional] The name of the Web (site) which contains the relationships list
    relationshipList: "", // The name of the list which contains the parent/child relationships
    relationshipListParentColumn: "", // The name of the parent column in the relationship list
    relationshipListChildColumn: "", // The name of the child column in the relationship list
    parentColumn: "", // The name of the parent column in the form
    childColumn: "" // The name of the child column in the form
    }, options);

    // Find the child column's multi-select possible values container
    var childSelectCtr = $().find("select:[Title='" + opt.childColumn + " possible values']");
    // Find the parent column's multi-select possible values container
    var parentSelectCtr = $().find("select:[Title='" + opt.parentColumn + " possible values']");               
    // Find the child column's multi-select selected values container
    var childSelectedCtr = $().find("select:[Title='" + opt.childColumn + " selected values']");
    // Find the parent column's multi-select selected values container
    var parentSelectedCtr = $().find("select:[Title='" + opt.parentColumn + " selected values']");
    // Find the parent column's multi-select add button
    var parentAddButton = parentSelectedCtr.parent().parent().parent().find("button:[id$=AddButton]");
    // Find the parent column's multi-select remove button
    var parentRemoveButton = parentSelectedCtr.parent().parent().parent().find("button:[id$=RemoveButton]");
    // Find the child column's multi-select remove button
    var childRemoveButton = childSelectedCtr.parent().parent().parent().find("button:[id$=RemoveButton]");

    var queryHead = null;
    var queryTail = null;
    var query = null;
    var buttonType = null;//1 for add button, 2 for remove button               

    parentAddButton.bind("click", function(){           
        //alert(parentSelectedCtr.find("option").size());
        if(parentSelectedCtr.find("option").size()>1){
            queryHead = "";
            queryTail = ""
        }
        else{
            queryHead = "";
            queryTail = "";
        }           
        query = queryHead;          
        parentSelectedCtr.find("option").each(function(){
            //alert($(this).text());
            var parentSelectedValue = $(this).text();
            query = query + "" + parentSelectedValue + "";
        });             
        query = query + queryTail;
        //alert(query);
        buttonType = 1;
        handleMultiSelect(childSelectCtr, childSelectedCtr, query, buttonType, opt);            
    });

    parentRemoveButton.bind("click", function(){            
        //alert(parentSelectCtr.find("option").size());             
        if(parentSelectCtr.find("option").size()>1){
            queryHead = "";
            queryTail = ""
        }
        else{
            queryHead = "";
            queryTail = "";
        }           
        query = queryHead;          
        parentSelectCtr.find("option").each(function(){
            //alert($(this).text());
            var parentSelectedValue = $(this).text();
            query = query + "" + parentSelectedValue + "";
        });             
        query = query + queryTail;
        //alert(query);         
        buttonType = 2;
        handleMultiSelect(childSelectCtr, childSelectedCtr, query, buttonType, opt);            
    });     

    childRemoveButton.bind("click", function(){         
        //alert(parentSelectCtr.find("option").size());             
        if(parentSelectCtr.find("option").size()>1){
            queryHead = "";
            queryTail = ""
        }
        else{
            queryHead = "";
            queryTail = "";
        }           
        query = queryHead;          
        parentSelectCtr.find("option").each(function(){
            //alert($(this).text());
            var parentSelectedValue = $(this).text();
            query = query + "" + parentSelectedValue + "";
        });             
        query = query + queryTail;
        //alert(query);
        buttonType = 2;
        handleMultiSelect(childSelectCtr, childSelectedCtr, query, buttonType, opt);        
    });  

    if(parentSelectedCtr.find("option").html() == null){
        if (childSelectCtr.find("option").html() != null) {
            childSelectCtr.find("option").each(function() {
                $(this).remove();
                childSelectCtr.trigger("change");
            });
        }
    }
    else{
        childRemoveButton.trigger("click");
    }
}

function handleMultiSelect(childSelectCtr, childSelectedCtr, query, buttonType, opt){     

    $().SPServices({
        operation: "GetListItems",
        // Force sync so that we have the right values for the child column onchange trigger
        async: false,
        webURL: opt.relationshipWebURL,
        listName: opt.relationshipList,
        // Filter based on the currently selected parent column's value
        CAMLQuery: query,
        // Only get the parent and child columns
        CAMLViewFields: "",
        // Override the default view rowlimit and get all appropriate rows
        // Took out  node because it was causing the CAML query to return duplicate rows
        CAMLRowLimit: "",
        completefunc: function(xData, Status){
            $(xData.responseXML).find("z\\:row").each(function(){
                if(buttonType == 1){
                    //Build the option
                    var optionToAdd = "" + $(this).attr("ows_" + opt.relationshipListChildColumn) + "";
                    //Add the option to the select list
                    if ((childSelectedCtr.find("option[value='" + $(this).attr("ows_ID") + "']").val() == undefined) && (childSelectCtr.find("option[value='" + $(this).attr("ows_ID") + "']").val() == undefined)) {
                        childSelectCtr.append(optionToAdd);
                    }
                }
                if(buttonType == 2){                        
                    if(childSelectedCtr.find("option[value='" + $(this).attr("ows_ID") + "']").val() != undefined) {
                        childSelectedCtr.find("option[value='" + $(this).attr("ows_ID") + "']").remove();
                    }
                    if(childSelectCtr.find("option[value='" + $(this).attr("ows_ID") + "']").val() != undefined){
                        childSelectCtr.find("option[value='" + $(this).attr("ows_ID") + "']").remove();
                    }
                }
            });
        }
    }); 
}
  • Thanks. I'll try this. Now to just figure out how to edit to work for me. – David Bowie Jul 17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.