Update fetch query of System/User view dynamically

By | August 25, 2014

Based on the client requirement sometimes it is needed to update the system/user view to filter record as per needed. In your query you need to apply outer join which won’t be possible through Advanced Find so in that case you need to update the fetch query of System/User view dynamically. Below is the sample code how to update the fetch query of system/user view dynamically using link type as Outer Join. Below is the query which describes that show only those active contacts with no opportunity exist in contact and those opportunities which was not closed in last 9 months using Outer Join. Below query won’t be possible through advanced find.

string fetchXml = @”<fetch version=’1.0′ output-format=’xml-platform’ mapping=’logical’ distinct=’true’ >

<entity name=’contact’ >

<attribute name=’fullname’ />

<attribute name=’parentcustomerid’ />

<attribute name=’emailaddress1′ />

<attribute name=’telephone3′ />

<attribute name=’address1_city’ />

<link-entity name=’opportunity’ from=’customerid’ to=’contactid’ alias=’ab’ link-type=’outer’ >

<filter type=’or’ >

<condition attribute=’actualclosedate’ operator=’last-x-months’ value=’9′ />



<filter type=’and’ >

<condition attribute=’statecode’ operator=’eq’ value=’0′ />

<condition entityname=’ab’ attribute=’opportunityid’ operator=’null’ />




Entity view = newEntity(“savedquery”); OR Entity view = newEntity(“userquery”);

view[“fetchxml”] = fetchXml;

view.Id = newGuid(“8DF19B44-A073-40C3-9D6D-EE1355D8C4BA”);


You can get the GUID of view from the URL of view. Refer the below screenshot:


Note: The attributes you define in a fetch query to show in the view should match with the columns that have been added in the view manually. Refer the below screenshot: