简体   繁体   中英

Creating a custom lookup with Javascript

This code worked in 4.0, in 2011 when I try to set the value of the lookup I get an error with 'initializelookuppresence'

4.0 Code

lookupCell.innerHTML = '<TABLE style="table-layout: fixed" class="ms-crm-Lookup" cellspacing="0" cellpadding="0" width="100%"><TBODY><TR><TD><DIV class="ms-crm-Lookup" tabindex="1011" role="list" ime-mode="auto" ms-crm-hidden-nobehavior><UL style="float: left"></UL></DIV><LABEL class="ms-crm-Hidden-NoBehavior" for=' + id + '_ledit>Related Entity</LABEL><INPUT style="display: inline"  id='+ id +'_ledit class=ms-crm-Hidden-NoBehavior disabled tabIndex=1010 ime-mode="auto"></TD><TD class=Lookup_RenderButton_td width=25><IMG style="ime-mode: auto" id=' + id + ' class="ms-crm-Lookup ms-crm-ImageStrip-btn_off_lookup" title="Click to select a value for Company." alt="Click to select a value for Company." src="/_imgs/imagestrips/transparent_spacer.gif" savedquerytype="" forfield=' + label + ' isDisplayOnly="False"  resolveemailaddress="0" disableviewpicker="0" disablequickfind="0" disablemru="0" allowfilteroff="1" AutoResolve="1" additionalparams=""  defaulttype="2" lookupstyle="single" lookupbrowse="0" lookuptypeIcons="/_imgs/ico_16_2.gif:/_imgs/ico_16_8.gif" lookuptypenames="contact:2:Contact,systemuser:8:User" lookuptypes="2,8" attrpriv="7"  req="1" _lookupstyle="single" _lookuptypes="2,8" _lookupbrowse="0"><A title="Click to select a value for Company." tabIndex=-1 onclick=previousSibling.click(); href="#"></A></TD></TR></TBODY></TABLE>';

Has anyone tried this successfully in 2011?

You are replacing the lookup control completely. It is not rendered with the same HTML in 2011 as it was in 4.0. Any messing with these control's HTML is unsupported. However, I see some overriding of the entity lookup types there... and Im guessing that is all you are looking to achieve, correct? The (also unsupported) way of achieving this is to override the element's attributes (rather than the entire control).

document.getElementById("parentcustomerid").setAttribute("lookuptypes","2");
document.getElementById("parentcustomerid").setAttribute("lookuptypenames", "contact:2"); document.getElementById("parentcustomerid").setAttribute("lookuptypeIcons", "/_imgs/ico_16_2.gif"); document.getElementById("parentcustomerid").setAttribute("defaulttype", "2");

I found the comments in Rhett's post here quite useful for more details on that.

Hope that helps.

我认为您需要以下

Xrm.Page.getAttribute(“fieldName”).setValue([new {id: idValue, name: textValue, entityType: typeValue}]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM