I have a Multi select Look up column which as you all know is a control with two list boxes and "Add or Remove" Buttons.
The user populates the right-hand side of the control with some values by clicking the Add button; I have saved those selected values into array. Now the user changes an option in a cascading dropdown which actually populates this multi select lookup column.
Normally in this scenario, the default values are loaded into the left-hand side of the look up with the right-hand "Responsibility selected values" being blank. What I want to do is to load the right-hand listbox with the values stored in array.
I am open to a solution which is based on both jQuery and JavaScript Client Object Model. I haven't been successful so far. :( Please help.
var newarry = new Array();
$("[title='System']").change(function() {
var responsibilityval = "";
if (newarry.length > 0) {
$.each(newarry, function(i) {
if (newarry[i] != '') {
alert(newarry[i]);
var mySelect = $("[title='Unit']");
mySelect.prepend("<option value='0'>Before Apples</option>");
}
});
}
});
I tried other options like but it didn't work
var mySelect = $("[title='Unit']");
mySelect.val(1)
Javascript object model sample
function getWebSiteData() {
clientContext = new SP.ClientContext.get_current();
if (this.clientContext != undefined && clientContext != null) {
var webSite = clientContext.get_web();
oList = webSite.get_lists().getByTitle("Add New User");
$.urlParam = function(name) {
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
var itemid = parseInt($.urlParam('ID'));
oListItem = oList.getItemById(itemid);
var listinfo = new SP.ListItemCreationInformation();
var item = oList.addItem(listinfo);
var fields = ['Responsibility'];
$(fields).each(function() {
var fieldName = this;
var field = $("#" + fieldName);
var fieldValue = field.val();
var entries = [];
var newitem = new SP.FieldLookupValue();
newitem.set_lookupId(1);
entries.push(newitem);
item.set_item(fieldName, entries);
});
item.update();
oList.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
}
function success(sender, args) {
alert('success');
}
function failed(sender, args) {
alert("failed. Message:" + args.get_message());
}