Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:06:59+00:00 2026-06-04T22:06:59+00:00

I’m creating search shortcuts from the quick search box for certain entities. This is

  • 0

I’m creating search shortcuts from the quick search box for certain entities. This is to avoid multiple returns especially when a name could contain a city name. (City searches are relevant, so it has to stay)

I’m accomplishing this via a plugin. So a user enters

/name Todd Richardson

In the search box on the contact entity view.

Update

This intercepts (pre-operation stage:20 prevalidation stage:10) the Retrievemultiple request for a contact.

End Update

Update As requested here is the beginning of the implementation as generated and then modified from the MSCRM 2011 sdk tools Please remember that this code is in a prototypical state, and may not be suitable for production code:

protected void ExecutePreAccountRetrieveMultiple(LocalPluginContext localContext)
    {
        if (localContext == null)
        {
            throw new ArgumentNullException("localContext");
        }

        if (localContext.PluginExecutionContext.InputParameters.Contains("Query"))
        {
            if (localContext.PluginExecutionContext.InputParameters["Query"] is QueryExpression)
            {
                //query expression from input is assigned to a local variable for modification.
                QueryExpression qe = (QueryExpression)localContext.PluginExecutionContext.InputParameters["Query"];

                if (qe.Criteria != null)
                {
                    if (qe.Criteria.Filters.Count > 1)
                    {
                        string entitySubject = qe.EntityName;
                        string searchSubject = qe.Criteria.Filters[1].Conditions[0].Values[0].ToString();


                         string namePattern = @"^([/\\-])+N(AME)?:?[\s]*(.+$)";

 //.... Eliminated for brevity, only including branch thats relevant to this question.


if (Regex.IsMatch(searchSubject.TrimEnd("%".ToCharArray()), namePattern, RegexOptions.IgnoreCase))
                            {
                                var Match = Regex.Match(searchSubject.TrimEnd("%".ToCharArray()), namePattern, RegexOptions.IgnoreCase);


                                if (Match.Groups.Count > 1)
                                {
                                    int lastIndex = Match.Groups.Count - 1;
                                    string name = Match.Groups.Cast<Group>().Last().Value;
                                    Func<string, List<ConditionExpression>> genXpress = (n) =>
                                    {

                                        List<ConditionExpression> ce = new List<ConditionExpression>();

                                        foreach (var val in name.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(x => string.Format("%{0}%", x)))
                                        {
                                            ce.Add(new ConditionExpression
                                            {
                                                Operator = ConditionOperator.Like,
                                                AttributeName = n,
                                                Values = { val }
                                            });
                                        }
                                        return ce;
                                    };

                                    if (entitySubject == "contact")
                                    {

                                        string[] names = name.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                        if (names.Length > 1)
                                        {
                                            string fn = names[names.Length - 2];
                                            string ln = names[names.Length - 1];

                                            string fetchRequest =
@"<?xml version=""1.0""?>
<fetch distinct=""false"" mapping=""logical"" output-format=""xml-platform"" version=""1.0""> 
    <entity name=""contact""> <attribute name=""fullname""/> 
    <attribute name=""telephone1""/> <attribute name=""contactid""/> 
    <order descending=""false"" attribute=""fullname""/> 
        <filter type=""and""> 
            <filter type=""or""> 
                <filter type=""and""> 
                    <condition attribute=""lastname"" value=""%%lastname%%"" operator=""like""/> 
                    <condition attribute=""firstname"" value=""%%firstname%%"" operator=""like""/> 
                </filter>  
                <filter type=""and""> 
                    <condition attribute=""lastname"" value=""%%firstname%%"" operator=""like""/> 
                    <condition attribute=""firstname"" value=""%%lastname%%"" operator=""like""/> 
                </filter>
            </filter> 
        </filter> 
    </entity> 
</fetch>" //

                                            .Replace("%lastname%", ln).Replace("%firstname%", fn);


                                            var conversionRequest = new FetchXmlToQueryExpressionRequest
                                            {
                                                FetchXml = fetchRequest
                                            };
                                            var response = (FetchXmlToQueryExpressionResponse)localContext.OrganizationService.Execute(conversionRequest);

                                            localContext.PluginExecutionContext.OutputParameters["Query"] = response.Query;
                                            return;
                                        }
                                        //variable modified and now passed out for execution.
                                        localContext.PluginExecutionContext.OutputParameters["Query"] = qe;


                                        return;
                                    }
                                }
                            }  //Remainder of code eliminated for different logic branches.

End update

A query expression is generated and put into the output parameter named query.

Originally I was building the QueryExpression.I was finding that this did not work. No matter how I built my query expression, I was getting

condition1 || condition 2 || condition3 || condition4 

So I took another angle. I went to the Advanced find and created a query that returned exactly what I wanted in the Results. I downloaded the fetch-xml and now this is what I have (as seen in the code previous):

string fetchRequest =
@"<?xml version=""1.0""?>
<fetch distinct=""false"" mapping=""logical"" output-format=""xml-platform"" version=""1.0""> 
    <entity name=""contact""> <attribute name=""fullname""/> 
    <attribute name=""telephone1""/> <attribute name=""contactid""/> 
    <order descending=""false"" attribute=""fullname""/> 
        <filter type=""and""> 
            <filter type=""or""> 
                <filter type=""and""> 
                    <condition attribute=""lastname"" value=""%%lastname%%"" operator=""like""/> 
                    <condition attribute=""firstname"" value=""%%firstname%%"" operator=""like""/> 
                </filter>  
                <filter type=""and""> 
                    <condition attribute=""lastname"" value=""%%firstname%%"" operator=""like""/> 
                    <condition attribute=""firstname"" value=""%%lastname%%"" operator=""like""/> 
                </filter>
            </filter> 
        </filter> 
    </entity> 
</fetch>" //

Whether I was generating the Queryexpression in code, or fetching it from the organization service, it seems to get me the same result. Instead of

(condition1 && condition2) || (condition3 && condition4) 

fulfilling the criteria, it basically ends up

condition1 || condition2 || condition3 || condition4 

I’ve tried other variations on the fetch xml, including:

string fetchRequest =  @"<?xml version=""1.0""?>
<fetch distinct=""false"" mapping=""logical"" output-format=""xml-platform"" version=""1.0""> 
    <entity name=""contact""> <attribute name=""fullname""/> 
    <attribute name=""telephone1""/> <attribute name=""contactid""/> 
    <order descending=""false"" attribute=""fullname""/> 
        <filter type=""and""> 
                <condition attribute=""lastname"" value=""%%lastname%%"" operator=""like""/> 
                <condition attribute=""firstname"" value=""%%firstname%%"" operator=""like""/> 
        </filter> 
    </entity> 
</fetch>"

Again this ends up being

condition1 || condition2

not

condition1 && condition2

Anyone have any clue as to what is going on. Is there a different fetchxml I should be using? Is this a bug? The answer has been elluding me for a better part of the day.

Hopefully it’s just something easy that I’m overlooking.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:07:01+00:00Added an answer on June 4, 2026 at 10:07 pm

    You are adding the modified query to the OutputParameters collection. This is not correct; the CRM event pipeline does not expect Query parameters to be in this collection and therefore ignores it. This is why you do not see the desired resultset.

    You must replace the existing Query parameter in the InputParameters collection with the one you modified.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.