Michael Philip's Blog

Writing about MS Tech with strong focus on Azure & CRM

Leave a comment

Dynamcis 365 – Override Lookup view using Java script


I have encountered some scenarios  in which I needed to override lookup view columns or apply some filters on the results depending on dynamics conditions at run time on CRM form.

In order to do that , add the following piece of code in the on load event

The following example filters results set no a specific case type


var viewId = “{00000000-0000-0000-0000-000000000001}”;

//add the entity name
var entityName = “incident”;

// add the view display name
var viewDisplayName = “Problem Cases”;

var fetchXml = “<fetch version=’1.0′ output-format=’xml-platform’ mapping=’logical’ distinct=’false’>” +
“<entity name=’incident’>” +
” <attribute name=’title’ />” +
“<attribute name=’customerid’ />” +
“<attribute name=’incidentid’ />” +
“<order attribute=’title’ descending=’false’ />” +
“<filter type=’and’>” +
“<condition attribute=’bps_type’ operator=’eq’ value=’200000005′ />” +
” </filter>” +
” </entity>” +

var layoutXml = “<grid name=’resultset’ object=’1′ jump=’productid’ select=’1′ icon=’1′ preview=’1′>” +
“<row name=’result’ id=’incidentid’>” +
“<cell name=’title’ width=’150′ />” +
“<cell name=’customerid’ width=’150′ />” +
“</row>” +

Xrm.Page.getControl(“parentcaseid”).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);