Dynamics CRM Javascript · Javascript

Dynamics CRM 365 Deep dive into Xrm.Utility.lookupObjects

To open lookup control on HTML web resource use below code.

function openMarketingList() {
var imgButton = $("#crmOtherLookup").attr("src");
if (imgButton == "/_imgs/btn_off_lookup.png") {
var objectTypeCode = 4300;
var lookupParameters = {};

//specify the list of entity types to be displayed in lookup dialog

lookupParameters.entityTypes = ["list"];

//Sepecify the default entityType need to be displayed

lookupParameters.defaultEntityType = "list";

//Default view need to be displayed

lookupParameters.defaultViewId = "{7D7737D8-1A05-4ABB-BEBD-843404A83DAD}";

//allow multiple selection or not

lookupParameters.allowMultiSelect = false;

//Decides whether to display the most recently used(MRU) item. Available only for Unified Interface.
lookupParameters.disableMru = false;
parent.window.Xrm.Utility.lookupObjects(lookupParameters).then(DisplaySelectedMarketingList, null);

}
}

Properties which can be set while opening lookup control

//allow multiple selection or not
lookupParameters.allowMultiSelect = false;

//Decides whether to display the most recently used(MRU) item. Available only for Unified Interface.
lookupParameters.disableMru = false;

//Default view need to be displayed
lookupParameters.defaultViewId = “{7D7737D8-1A05-4ABB-BEBD-843404A83DAD}”;

To get the selected record details, add below code as callback defined in lookupobject

function DisplaySelectedMarketingList(selectedMarketingList) {
if (selectedMarketingList != undefined && selectedMarketingList != null && selectedMarketingList != "") {
var guid = selectedMarketingList[0].id;
var name = selectedMarketingList[0].name;
}
}

To Apply filter while opening lookup control, Use below code

lookupParameters.filters = [{
filterXml: "<filter type='and'><condition attribute='new_campaign' operator='eq' value='" + campaignGuid + "' /></filter>",
entityLogicalName: "new_aememail"
}];

HTML Web resource code where lookupobject is used

<tr>
<td valign=”top”>
<label hidefocus=”true” for=”rdoOther”>
<b>Select Marketing List</b>
</label>

</td>
<td valign=”top”>
<table width=”100%” style=”table-layout: fixed;” cellspacing=”0″ cellpadding=”0″>
<tbody>
<tr>
<td>
<table class=”ms-crm-Lookup” id=”crmOtherLookup_lookupTable” style=”width: 100%; table-layout: fixed;” cellspacing=”0″ cellpadding=”0″ lookupid=”crmOtherLookup”>
<tbody>
<tr>
<td valign=”top” style=”padding-right: 1px; padding-left: 1px;”>
<div tabindex=”0″ class=”ms-crm-Lookup ms-crm-ReadOnly ms-crm-Lookup-ReadOnly” role=”list” style=”width: 100%;” ime-mode=”auto”>
<!– <ul style=”width: 100%; text-align: left; float: left;”></ul> –>
<input type=”hidden” id=”crmMLOtherLookup_lId”>
</div>
<!– <label class=”ms-crm-Hidden-NoBehavior” for=”crmOwnerLookup_ledit”>Assign the selected Comment to the following user or team:</label> –>
<input disabled=”disabled” tabindex=”0″ class=”ms-crm-Hidden-NoBehavior” id=”crmMLLookup_ledit” style=”padding: 2px 0px 1px; height: 100%; border-right-color: currentColor; border-right-width: 0px; border-right-style: none; display: inline;” type=”text” maxlength=”1000″ ime-mode=”auto”>
</td>
<td class=”Lookup_RenderButton_td” style=”width: 21px;”>
<img title=”Click to select a Campaign to send an Email:” class=”ms-crm-Lookup ms-crm-ImageStrip-btn_dis_lookup” id=”crmOtherLookup” style=”cursor: default;” alt=”Click to select a Campaign to send an Email” src=”/_imgs/btn_off_lookup.png” forcesubmit=”false” isenableinlinelookupforeditforms=”1″ lookupstyle=”single” lookuptypes=”8″ lookuptypenames=”systemuser:8:User” lookuptypeicons=”/_imgs/ico_16_8.gif?ver=-889823255″ onclick=”openMarketingList();”>
<a tabindex=”-1″ title=”Click to select a Campaign to send an Email” onclick=”openMarketingList();” href=”#”></a>
</td>
</tr>
</tbody>
</table>

</td>
</tr>
</tbody>
</table>

</td>
</tr>

Hope this helps!

2 thoughts on “Dynamics CRM 365 Deep dive into Xrm.Utility.lookupObjects

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s