Quantcast
Viewing all articles
Browse latest Browse all 6517

New Post: Add to List if not in Drop Down

Heres a version that works with muklti select options pn my test environment (2010)/ To useit just set the dialogReturnValueCallback of your dialog options to your version of the function below.

function CounterpartyAdded(value, returnValue) {// if user canceled out of the add dialogif (value == '0') {return;
    }// get the id of the item the user just added note that spGetLastItemID gets the item added bu the CURRENT USERvar lastItemID = $().SPServices.SPGetLastItemId({ listName: "TESTLOOKUP" });  // REPLACE TESTLOOKUP WITH THE NAME OF YOUR LOOKUPLIST // get the listbox on the right that holds the values the user has selectedvar selectedValueDisplay = $("select[Title='TESTLOOKUPCOLUMNS selected values']")[0]; //REPLACE  TESTLOOKUPCOLUMNS WITH THE NAME OF YOUR COLUMNif (selectedValueDisplay !== null) {// Get The item the user JUST Addedvar myQuery = "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + lastItemID + "</Value></Eq></Where></Query>";
        $().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "TESTLOOKUP",  //REPLACE TESTLOOKUP WITH THE NAME OF YOUR LOOKUPLIST 
            CAMLViewFields: "",
            CAMLQuery: myQuery,
            completefunc: function (xData, Status) {// get the row returned (should only be one!)
                $(xData.responseXML).find("[nodeName='z:row']").each(function () {// add the item to the listbox on the left (the selected Values)var newOption=new Option($(this).attr("ows_Title"), $(this).attr("ows_ID"));///newOption.title=$(this).attr("ows_Title"); // need to set this also, for some reason
               selectedValueDisplay.options[selectedValueDisplay.length]=newOption;// now find the previous Input whose name or id  ends with 'MultiLookupPicker'// this contains  values that will get saved to the listitemvar MultiLookupPicker=$(selectedValueDisplay).closest("span").find("input:[name$='MultiLookupPicker']");var s="";for (var i=0; i < selectedValueDisplay.options.length; i++)
				{if (s !="")
						s=s+"|t";
					s=s+selectedValueDisplay.options[i].value.replace("|","||");
					s=s+"|t";
					s=s+selectedValueDisplay.options[i].text.replace("|","||");
				}
			$(MultiLookupPicker)[0].value=s;debugger;

                });
            }
        });

    }
}

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>