creating view for lookup in ms crm
var accountId = null;
var APPVersion = null;
try {
APPVersion = APPLICATION_VERSION;
}
catch (e) {
APPVersion = parent.APPLICATION_VERSION;
}
var entityName = Xrm.Page.data.entity.getEntityName();
if (entityName == "account" || enityName == "contact") {
var accountObj = Xrm.Page.getAttribute("mtctb_accountid").getValue();
}
if (accountObj != null) {
if (accountObj.length == 0) {
accountObj = null;
return;
}
accountId = accountObj[0].id.replace("{", "").replace("}", "");
}
if (accountId != null) {
var viewId = "{00000000-0000-0000-0000-100000000001}";
var entName = "contact";
var viewName = "Account Related Contacts";
var conFetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='contact'>" +
"<attribute name='fullname' />" +
"<attribute name='telephone1' />" +
"<attribute name='contactid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='parentcustomerid' operator='eq' uiname='A. Datum Corporation (sample)' uitype='account' value='{" + accountId + "}' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var conLayoutXml = "<grid name='resultset' object='2' jump='lastname' select='1' icon='1' preview='1'>" +
"<row name='result' id='contactid'>" +
"<cell name='fullname' width='200'/>" +
"<cell name='telephone1' width='125'/>" +
"<cell name='parentcustomerid' width='100'/>" +
"<cell name='emailaddress1' width='150'/>" +
"</row>" +
"</grid>";
Xrm.Page.getAttribute("mtctb_contactid").setValue(null);
if (APPVersion <= "7.0") {
Xrm.Page.getControl("mtctb_contactid").addCustomView(viewId, entName, viewName, conFetchXml, conLayoutXml, true);
$("#mtctb_contactid").find("img").attr("disableviewpicker", "1");
}
else {
try {
document.getElementById("mtctb_contactid").addCustomView(viewId, entName, viewName, conFetchXml, conLayoutXml, true);
document.getElementById("mtctb_contactid").attributes.disableviewpicker.value = "1";
}
catch (e) {
parent.document.getElementById("mtctb_contactid").addCustomView(viewId, entName, viewName, conFetchXml, conLayoutXml, true);
parent.document.getElementById("mtctb_contactid").attributes.disableviewpicker.value = "1";
}
}
}
var APPVersion = null;
try {
APPVersion = APPLICATION_VERSION;
}
catch (e) {
APPVersion = parent.APPLICATION_VERSION;
}
var entityName = Xrm.Page.data.entity.getEntityName();
if (entityName == "account" || enityName == "contact") {
var accountObj = Xrm.Page.getAttribute("mtctb_accountid").getValue();
}
if (accountObj != null) {
if (accountObj.length == 0) {
accountObj = null;
return;
}
accountId = accountObj[0].id.replace("{", "").replace("}", "");
}
if (accountId != null) {
var viewId = "{00000000-0000-0000-0000-100000000001}";
var entName = "contact";
var viewName = "Account Related Contacts";
var conFetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='contact'>" +
"<attribute name='fullname' />" +
"<attribute name='telephone1' />" +
"<attribute name='contactid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='parentcustomerid' operator='eq' uiname='A. Datum Corporation (sample)' uitype='account' value='{" + accountId + "}' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var conLayoutXml = "<grid name='resultset' object='2' jump='lastname' select='1' icon='1' preview='1'>" +
"<row name='result' id='contactid'>" +
"<cell name='fullname' width='200'/>" +
"<cell name='telephone1' width='125'/>" +
"<cell name='parentcustomerid' width='100'/>" +
"<cell name='emailaddress1' width='150'/>" +
"</row>" +
"</grid>";
Xrm.Page.getAttribute("mtctb_contactid").setValue(null);
if (APPVersion <= "7.0") {
Xrm.Page.getControl("mtctb_contactid").addCustomView(viewId, entName, viewName, conFetchXml, conLayoutXml, true);
$("#mtctb_contactid").find("img").attr("disableviewpicker", "1");
}
else {
try {
document.getElementById("mtctb_contactid").addCustomView(viewId, entName, viewName, conFetchXml, conLayoutXml, true);
document.getElementById("mtctb_contactid").attributes.disableviewpicker.value = "1";
}
catch (e) {
parent.document.getElementById("mtctb_contactid").addCustomView(viewId, entName, viewName, conFetchXml, conLayoutXml, true);
parent.document.getElementById("mtctb_contactid").attributes.disableviewpicker.value = "1";
}
}
}
Comments
Post a Comment