To filter the view behind a lookup so this it will retrieve only some of the elements based on a filter it can be done follwing the steps:
1)Set the id Guid of the View, it can be a random Guid.
var viewId = "{10109D21-27F7-4828-B131-1B5E972C4718}"; //Any Guid is fine.
2)Set the entity name to be filtered
var entityName = "new_test";// Entity to be filtered
3)Set the name for the custom view
var viewDisplayName = "Test View"; // Custom name for the lookup window
4)Create the query that you want to retrieve. You can use Advanced Search to make it more quickly, or you can build it yourself .
var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXML += "<entity name='new_test'>";
fetchXML += "<attribute name='new_name'/>";
fetchXML += "<attribute name='new_code' />";
fetchXML += "<filter type='and'>";
fetchXML += "<condition attribute='new_name' operator='like' value='%abc%'/>";
fetchXML += "</filter>";
fetchXML += "</entity>";
fetchXML += "</fetch>";
5)Create the layout which will be displayed in the lookup
var layoutXML = "<grid name='resultset' object='1' jump='new_primary' select='1' icon='1' preview='1'>";
layoutXML += "<row name='result' id='new_name'>";
layoutXML += "<cell name='new_code' width='150' />";
layoutXML += "</row>";
layoutXML += "</grid>";
6) Assign the custom view to the desired control:
Xrm.Page.getControl("new_testControl").addCustomView(viewId, entityName, viewDisplayName, fetchXML , layoutXML, true);
The full script is:
var viewId = "{10109D21-27F7-4828-B131-1B5E972C4718}"; //Any Guid is fine.
var entityName = "new_test";// Entity to be filtered
var viewDisplayName = "Test View"; // Custom name for the lookup window
var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXML += "<entity name='new_test'>";
fetchXML += "<attribute name='new_name'/>";
fetchXML += "<attribute name='new_code' />";
fetchXML += "<filter type='and'>";
fetchXML += "<condition attribute='new_name' operator='like' value='%abc%'/>";
fetchXML += "</filter>";
fetchXML += "</entity>";
fetchXML += "</fetch>";
var layoutXML = "<grid name='resultset' object='1' jump='new_primary' select='1' icon='1' preview='1'>";
layoutXML += "<row name='result' id='new_name'>";
layoutXML += "<cell name='new_code' width='150' />";
layoutXML += "</row>";
layoutXML += "</grid>";
Xrm.Page.getControl("new_testControl").addCustomView(viewId, entityName, viewDisplayName, fetchXML , layoutXML, true);
No comments:
Post a Comment