Exclude members from a list in Dynamics CRM 4 and 2011
Just as the title says I need to exclude members from a list. I've tried using advanced find to come up with the xml query however I haven't made much progress.
What I am trying to do is to process an action on a list based on whether or not the user wants the action to happen to those who have specifically accepted the agreement and only those members or a second option to pr开发者_如何学Cocess that action on everyone who has not specifically declined the agreement whether they have accepted or not done either.
What I need is to look for everyone who has declined an agreement and select everyone else from the list. When the member declines the agreement an entity is created to reflect that. This works well for those that accept the agreement. However I'm having trouble selecting everyone who doesn't have this entity associated with them.
I hope that's not too confusing...
To achieve this in SQL, you typically do a Left Outer join to combine people with agreements, and then filter out everyone with a non-null agreement.
You won't believe me when I tell you that this isn't possible in Dynamics CRM.
It's possible to do an Outer join, although it requires manual editing of the XML query via export/import. However, thanks to FetchXML's inability to reference items from inside the <linked-entity>
in a top-level <filter>
clause, the Outer Join is next-to useless. If you <filter>
inside the <link-entity>
, this is translated into the Join's ON clause, which is not equivient to the WHERE clause for Outer Joins.
This is a shocking ommission from Dynamics CRM.
The cryptic note at the bottom of this article tries to explain this: http://msdn.microsoft.com/en-us/library/ms936574.aspx
Well, first off... It boggles my mind why they wouldn't include a way to exclude members from a list... Is there any reason for that I'm just not seeing? I can't imagine there is but I still know so little...
I have managed to make this work though after a few redesigns. We grab the whole list of people and do an outter join with those who have declined and add the declined date to it.
declinedNode = entityNode.GetChildNode("link-entity", "link-entity[@name='xx_decline_{0}']".FormatWith(memberType));
declinedNode.SetAttribute("name", "xx_decline_{0}".FormatWith(memberType));
declinedNode.SetAttribute("from", "xx_parent_{0}id".FormatWith(memberType));
declinedNode.SetAttribute("to", "{0}id".FormatWith(memberType));
declinedNode.SetAttribute("link-type", "outer");
declinedNode.SetAttribute("alias", "declined");
var declinedDateNode = fetchXmlDoc.CreateNode(XmlNodeType.Element, "attribute", string.Empty);
declinedDateNode .SetAttribute("name", "xx_declineddate");
declinedNode.AppendChild(declinedDateNode);
Then server side were already looping through all the members in the list so we just put a condition that it if it had a value for the declined date we ignore it.
精彩评论