Multi Select Lookup Cross Browser CRM 2011 Update Rollup 12

We have created a multiselect lookup in crossbrowser in crm 2011.You have to create a hidden field(Single Line of Text) to store multiselect lookup values
You have to replace name of fields with your fields name.
Following Script help You.


function onLoad() {

    document.getElementById("lookupname")._behaviors[0].set_lookupStyle("multi");
  
    var data = new Array();
     // hidden field storing multi lookupvalue
    var store = Xrm.Page.getAttribute("hiddenfieldname").getValue();

    if (store != null) {
        data = store.split(";");

        var typename = "lookupentityname";

        var arr = new Array();
        var i = 0;
        var j = 0;

        for (i = 0; i < ((data.length - 1) / 2); i++) {

            arr[i] = new Object();

            arr[i].name = data[j];

            arr[i].id = data[j + 1];
            arr[i].typename = typename;

            j++;
            j = j + 1;


        }

        document.getElementById("lookupname")._behaviors[0].set_dataValue(arr)
       

    }

}
function Onsave() {

     var value = document.getElementById("lookupname")._behaviors[0].get_dataValue();



    var s;
    var temp = "";
    if (value != null) {
        for (s = 0; s < value.length; s++) {

            var temp2 = "";

            temp2 = value[s].name + ";" + value[s].id + ";";
            temp = temp + "" + temp2;

        }

    }
   
    Xrm.Page.getAttribute("hiddenfieldname").setValue(temp);
    Xrm.Page.getAttribute("hiddenfieldname").setSubmitMode("always");
    Xrm.Page.getAttribute("lookupname").setValue(null);
    document.getElementById("lookupname")._behaviors[0].set_lookupStyle("single");
}

 

Regards

Crm Blog 2011 Team

Comments

  1. This worked great in Chrome for me, but had issues in Firefox. Upon saving firefox would ask me to submit an error report to MS if I had more than 1 entity in the lookup field. Would still save the entity properly, however.
    Doesn't throw the error if I open an entity with multiple lookups already, as long as I don't change them.
    Couldn't figure out how to fix it, but a workaround is to disable submitting error reports to MS in CRM options.

    ReplyDelete
  2. the same code works for me in chrome and in safari browser in desktop... but it is not working in iPAD. strange !!!!!!!!!!

    ReplyDelete
  3. Thanks its working for me. Nice articel

    ReplyDelete

Post a Comment

Popular Posts