MSCRM 2011 LOOKUP Multi Value
Hi This is Sudhakar Reddy Chidipudi
Below you can see i wrote two functions ,OnSave of the form you can get the multiple values from lookup and save those values in a multiline text box.
To use the below code you need a lookup and one multiline text box.
//Form Onload
function load()
{
document.getElementById("Your lookup Schema Name").setAttribute("lookupstyle", "multi");
document.getElementById("Your lookup Schema Name").setAttribute("_lookupstyle", "multi");
if(Xrm.Page.ui.getFormType()!=1)
{
var data=new Array();
// I created a one multiline text box to save the lookup values.
// set the multiline textbox visible equal to false.
var store=Xrm.Page.getAttribute("new_textbox").getValue();
data=store.split(";");
// To get the "Target record type" Go to your form Customization ---> double click on your lookup--->Details--->Edit--->Here you can see "Target Record Type"
var typename = "Target Record Type";
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;
}
crmForm.all["Your lookup Schema Name"].DataValue = arr;
}
}
//Form OnSave
function save()
{
var value = crmForm.all["Your lookup Schema Name"].DataValue;
var s;
var temp="";
for (s=0;s<value.length;s++)
{
var temp2="";
temp2=value[s].name+";"+value[s].id+";";
temp=temp+""+temp2;
}
Xrm.Page.getAttribute("new_textbox").setValue(temp);
Xrm.Page.getAttribute("Your lookup Schema Name").setValue(null);
document.getElementById("Your lookup Schema Name").setAttribute("lookupstyle", "single");
}
Have a nice day.................................
Sudhakar Reddy Chidipudi