Hello Experts,
I have copied the code below from another post in this forum. and wanted to use it to update a system view. However, when I use "SavedQuery sq = new SavedQuery{ }"
Visual Studio tells me: "The type or namespace name 'type/namespace' could not be found (are you missing a using directive or an assembly reference?) Compiler Error CS0246".
Am I missing any reference? Here are the ones I use:
using System;
using System.Linq;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
One Doc I found is this one: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/savedquery?view=dynamics-ce-odata-9
I tried to add Microsoft.Crm.Sdk; without any success. Maybe the wrong documentation?
I hope someone can help me or point me into the right direction.
Thanks in advance !
The code below is the one I've copied:
System.String layoutXml =
@"<grid name='resultset' object='3' jump='name' select='1'
preview='1' icon='1'>
<row name='result' id='opportunityid'>
<cell name='name' width='150' />
<cell name='customerid' width='150' />
<cell name='estimatedclosedate' width='150' />
<cell name='estimatedvalue' width='150' />
<cell name='closeprobability' width='150' />
<cell name='opportunityratingcode' width='150' />
<cell name='opportunitycustomeridcontactcontactid.emailaddress1'
width='150' disableSorting='1' />
</row>
</grid>";
System.String fetchXml =
@"<fetch version='1.0' output-format='xml-platform'
mapping='logical' distinct='false'>
<entity name='opportunity'>
<order attribute='estimatedvalue' descending='false' />
<filter type='and'>
<condition attribute='statecode' operator='eq'
value='0' />
</filter>
<attribute name='name' />
<attribute name='estimatedvalue' />
<attribute name='estimatedclosedate' />
<attribute name='customerid' />
<attribute name='opportunityratingcode' />
<attribute name='closeprobability' />
<link-entity alias='opportunitycustomeridcontactcontactid'
name='contact' from='contactid' to='customerid'
link-type='outer' visible='false'>
<attribute name='emailaddress1' />
</link-entity>
<attribute name='opportunityid' />
</entity>
</fetch>";
SavedQuery sq = new SavedQuery
{
Name = "A New Custom Public View",
Description = "A Saved Query created in code",
ReturnedTypeCode = "Associated Hardware View",
FetchXml = fetchXml,
LayoutXml = layoutXml,
QueryType = 0
};
service.Update(sq); //service = IOrganizationService
Entity entity = new Entity("savedquery");
entity.Id = viewId;
entity["fetchxml"] = fetchXml;
entity["layoutxml"] = layoutXml;
service.Update(entity);