I'm trying to use the CRM Lookup in my own application. I want to get the ID
of the contact, I select in the lookup window.
Someone told me I should be able to receive the return value with the
following code:
var ret =
window.showModalDialog("http://<server>/_controls/lookup/lookupsingle.aspx?class=null&objecttypes=2,8&browse=0");
alert(ret.items[0].id);
But I always get the following Script error: "items is null or not an object"
Can someone tell me, how I can get the ID of the chosen contact? I don't
know how to get the right return value.
Thanks for your help!
Regards, Simon
var lookupItem = new Array;
// This will get the lookup for the attribute primarycontactid on the
Account form.
lookupItem = crmForm.all.primarycontactid.DataValue;
// If there is data in the field, show it in a series of alerts.
if (lookupItem[0] != null)
{
// The text value of the lookup.
alert(lookupItem[0].name);
// The entity type name.
alert(lookupItem[0].typename);
// The GUID of the lookup.
alert(lookupItem[0].id);
// The entity type code of the lookup: 1=account, 2= contact.
alert(lookupItem[0].type);
}
HtH
That's not what I mean. I want to use the lookup in my own site, my own
application. There I don't have access to the crmForm.
Regards, Simon
Is there a possibility to save the ret value from the Lookup form?
<body MS_POSITIONING="GridLayout" onload="javascript:LoadLookUp();">
<form name=frm id=frm >
<table ID="Table1">
<tr>
<td>Duplicate Defect Reference</td>
<td>
<table class="lu"
cellpadding="0" cellspacing="0" width="100%"
style="table-layout:fixed;"
ID="Table2">
<tr>
<td><div
class="lu" id=lu1 ></div>
</td>
<td width="25"
style="text-align: right;"><img
src="/_imgs/btn_off_lookup.gif" id="productid"
onclick="showlookup()"></td>
</tr>
</table>
</form>
</body>
this will be in html page ( i have used iframe for this )
function LoadLookUp()
{
if(top.IFRAME_first.frm.getElementsByTagName("div")[0]!= null)
{
var
obj2=top.IFRAME_first.frm.getElementsByTagName("div")[0];
//setting the lookup in the html form
var obj1=parent.document.createElement("SPAN");
obj1.className= "lui";
obj1.oid="";
//set the object type
obj1.otype="";
obj1.innerHTML="";
obj2.innerHTML=obj1.outerHTML;
}
}
no in the loadlookup you call ur own code
this will help you
Did you import any of the lookup js files?
Regards, Simon
i have imported this css file
showlookup() method write the function
var ret =
window.showModalDialog("http://<server>/_controls/lookup/lookupsingle.aspx?class=null&objecttypes=2,8&browse=0");
just place this file in the crmwebfolder
say you named this file as rakesh.html
http:\\<crmserver>\rakesh.html
if you place it any where else then you have to change the url for
lookup and the refrences
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>contact</title>
<link rel="stylesheet" type="text/css"
href="/_common/styles/global.css">
<link rel="stylesheet" type="text/css"
href="/_common/styles/fonts.aspx">
<link rel="stylesheet" type="text/css"
href="/_forms/controls/controls.css">
<link rel="stylesheet" type="text/css"
href="/_common/styles/select.css">
<link rel="stylesheet" type="text/css"
href="/_forms/controls/form.css">
<script language=javascript>
function showlookup()
{
var url;
url = "/_controls/lookup/lookupsingle.aspx";
url += "?class=null"
url += "&objecttypes=2"
url += "&browse=0"
var lookupItems = window.showModalDialog(url,"488px,498px");
alert(lookupItems.items[0].id);
}
function LoadLookUpFromDefectInfo()
{
var obj2=frm.getElementsByTagName("div")[0];
//setting the lookup in the html form
var obj1=parent.document.createElement("SPAN");
obj1.className= "lui";
obj1.oid="";
//set the object type
obj1.otype="";
obj1.innerHTML="";
obj2.innerHTML=obj1.outerHTML;
}
//------------------------------
function LoadLookUp()
{
LoadLookUpFromDefectInfo()
}
//------------------
</script>
</head>
<body MS_POSITIONING="GridLayout"
onload="javascript:LoadLookUp();">
<form name=frm id=frm >
<table ID="Table1">
<tr>
<td>Duplicate Defect Reference</td>
<td>
<table class="lu"
cellpadding="0" cellspacing="0" width="100%"
style="table-layout:fixed;"
ID="Table2">
<tr>
<td><div
class="lu" id=lu1 ></div>
</td>
<td width="25"
style="text-align: right;"><img
src="/_imgs/btn_off_lookup.gif" id="productid"
onclick="showlookup()"></td>
</tr>
</table>
</form>
</body>
</html>
Thanks very much! It's working now. I always tried to open the html file
directly in the crm folder instead of browsing to the file with the internet
explorer.
Thanks again!
May you know, how I can deactivate the "New" button in the lookup?
Regards, Simon