If I understand your question correctly, the only way to exclude the custom activity
from and include all the other activity
s in your Activity
views is to alter the views' underlying fetchXml
, either manually or by looping through the SavedQuery
entity (see below), to make sure the view doesn't reference the activity
. There's no flag that you can put in to stop your custom activity
from showing up in any particular activity
view; you need to alter all views to have this reflected (unless, of course, your custom entity
is not an activity
at all).
//using System.Xml.Linq;
//your list of activity entities excluding the special custom activity
string activityList = "<condition attribute=\"activitytypecode\" operator=\"in\"><value>4401</value><value>4204</value><value>10058</value></condition>";
XElement newFilter = XElement.Parse(activityList);
var sq = from q in xsc.SavedQuerySet
where q.ReturnedTypeCode == ActivityPointer.EntityLogicalName
select new
{
fetchXml = q.FetchXml
, queryId = q.SavedQueryId
, queryName = q.Name
};
foreach (var q in sq)
{
//do your xml parsing
XElement xml = XElement.Parse(q.fetchXml);
if (!xml.Elements("entity")
.Elements("filter").Where(x => x.Attributes("type").Single().Value == "and").Any())
{
xml.Elements("entity").Single().Add(XElement.Parse("<filter type=\"and\"></filter>"));
}
//some level of validation
if (!xml.Elements("entity")
.Elements("filter")
.Where(x => x.Attributes("type").Single().Value == "and")
.Single().Elements("condition")
.Where(x => x.Attributes("attribute")
.Single().Value == "activitytypecode")
.Where(x => x.Attributes("operator")
.Single().Value == "in").Any())
{
xml.Elements("entity")
.Elements("filter")
.Where(x => x.Attributes("type")
.Single().Value == "and")
.Single().Add(newFilter);
SavedQuery query = new SavedQuery();
query.SavedQueryId = q.queryId;
query.FetchXml = xml.ToString();
service.Update(query);
}
}
You'll need to publish after this to see your changes stick.