web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

addCustomFilter and addCustomView , DefaultView ,setDefaultView,addPreSearch,removePreSearch in Lookup control methods and events

(0) ShareShare
ReportReport
Posted on by 52
function OnLoad() {
	var fetchXml;
	var pattern = "Nam";
	function setCustomView() {
		var viewId = Xrm.Page.getControl("SubSV").getDefaultView();
		var entityName = "hoang_sinhvien";
		var viewDisplayName = "Filtered SinhVien";

		fetchXml="<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\"> "+
				 "<entity name=\"hoang_sinhvien\"><attribute name=\"hoang_name\" /><order attribute=\"hoang_name\" descending=\"false\" />"+
				 "<link-entity name=\"hoang
_dateofbirth\" form=\"hoang_dateofbirth\" to=\"hoang_dateofbirth\" alias=\"aa\"><filter type=\"and\">"+
				 
				 "<condition attribute=\"hoang_gender\" operator=\"eq\" value\""+
				 pattern + "\" /></filter></link-entity>" + 
				 "<attribute name=\"hoang_name\" /><attribute name=\"hoang_dateofbirth\" /><attribute name=\"hoang_sinhvienid\" /></entity></fetch>";

		var layoutXml ="<grid name=\"resultset\" object=\"10010\" jump=\"hoang_name\" select=\"1\" preview=\"1\" icon=\"1\">" +
				"<row name=\"result\" id=\"hoang_sinhvienid\"><cell name=\"hoang_name\" width=\"150\"/><cell name=\"hoang_dateofbirth\" width=\"100\"/>"+
				"<cell name=\"hoang_name\" width=\"100\"/></row></grid>";
		Xrm.Page.getControl("SubSV").addCustomView(viewId,entityName,viewDisplayName,fetchXml,layoutXml,true);      
	}
}

Hello, I'm a newbie, my problem is how to:
I am trying to create addCustomFilter and addCustomView ... as follows


I have a reference to this page: https://community.dynamics.com/crm/b/powerxrmblog/archive/2016/06/13/lookup-filtering-using-addcustomview 

I have a living entity. These include dateofbirth and gender fields
This is the fetchXML statement I want it to show only for male students and it worked but the viewDisplayName property does not appear in the Loop Up Record Look in box as shown below. Know where I am wrong in the code? the bottom and can make short of the tops of the code is not, Thank you!

aaqaqaqaqaaaa.png

*This post is locked for comments

I have the same question (0)
  • Verified answer
    David Jennaway Profile Picture
    14,065 on at

    I think the problem might be that you're using the existing viewId value. When you call addCustomView, the viewId should be unique, so you should generate a new viewId

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans