CRM 2011 Quick Find Search using default wildcard (*) automatically [closed]

拟墨画扇 提交于 2019-12-12 03:26:31

问题


I have tried the following which I found in another post but it doesn't seem to make a difference:

1.Go to the following path and find "stage.js" file "C:\Program Files\Microsoft Dynamics CRM\CRMWeb_static_common\scripts\"

2.Create a backup copy of this file before any modification, so that you have the original copy too

3.Open "stage.js" in a text editor such as EmEditor

4.Find the following line of code: sFindCriteria=Trim(findCriteria.value.replace(/[]+/,""));findCriteria.value=sFindCriteria;

5.Now change it to : sFindCriteria=Trim(findCriteria.value.replace(/[]+/,""));if (sFindCriteria != "" && sFindCriteria.substr(0, 1) != "") sFindCriteria = "" + sFindCriteria;findCriteria.value=sFindCriteria;

6.Save the file and try Quick Find to see the change

Any ideas why this doesn't work and what I can change to get this to work??


回答1:


I believe your talking about this post :P In Dynamics CRM, how do I enable wildcard (*) search by default in Quick Find?

I asked the same Question in 2014, but now i have got the solution. I agree with Henk van Boeijen modifying the built-in script is an un-supported way, so i found a supported way.

Write a plugin:

  public void Execute(IServiceProvider serviceProvider)
    {
        string OriginalSearchQueryString = String.Empty;
        string UpdatedOriginalQueryToLikeQuery = String.Empty;

        try
        {
            IPluginExecutionContext ContextInstance = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationService ServiceInstance = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(ContextInstance.InitiatingUserId);
            // Critical Point here - NOTICE that the InputParameters Contains the word Query
            if (ContextInstance.Depth < 2 && ContextInstance.InputParameters.Contains(QueryLiteral) && ContextInstance.InputParameters[QueryLiteral] is QueryExpression)
            {

                QueryExpression QueryPointer = (ContextInstance.InputParameters[QueryLiteral] as QueryExpression);
                //Verify the conversion worked as expected - if not, everything else is useless
                if (null != QueryPointer)
                {
                    // Check if the request is coming from any Search View 
                    // We know this b/c Criteria isn't null and the Filters Count > 1
                    if (null != QueryPointer.Criteria && (QueryPointer.Criteria.Filters.Count > 1 || QueryPointer.Criteria.Filters.Count == 1))
                    {
                        if (QueryPointer.Criteria.Filters.Count > 1 && QueryPointer.Criteria.Filters[0].Conditions.Count > 0 && QueryPointer.Criteria.Filters[0].Conditions[0].Values.Count > 0)
                            OriginalSearchQueryString = QueryPointer.Criteria.Filters[1].Conditions[0].Values[0].ToString();
                        else if (QueryPointer.Criteria.Filters.Count == 1 && QueryPointer.Criteria.Filters[0].Conditions.Count > 0 && QueryPointer.Criteria.Filters[0].Conditions[0].Values.Count > 0)
                            OriginalSearchQueryString = QueryPointer.Criteria.Filters[0].Conditions[0].Values[0].ToString();

                        if (CheckIfTheQueryIsNotForWebResourceAndSearchIsNotByLetter(ContextInstance.PrimaryEntityName, OriginalSearchQueryString))
                        {
                            OriginalSearchQueryString = String.Format(CultureInfo.CurrentCulture, "{0}{1}", LIKE, OriginalSearchQueryString);
                            OriginalSearchQueryString = ModifyAllConditionExpressionsInCriteriaToLikeOperator(OriginalSearchQueryString, QueryPointer);
                            ContextInstance.InputParameters[QueryLiteral] = QueryPointer;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Logger.Error("Exception occured in QuickSearch()", ex);
        }
    }


private bool CheckIfTheQueryIsNotForWebResourceAndSearchIsNotByLetter(string entityLogicalName, string originalSearch)
    {

        if (entityLogicalName.ToLower() == "webresource" || String.IsNullOrWhiteSpace(originalSearch) || entityLogicalName.ToLower() == "opportunity")
            return false;

        else if (originalSearch.StartsWith("[") && originalSearch.EndsWith("]%"))
            return false;

        return true;
    }


private string ModifyAllConditionExpressionsInCriteriaToLikeOperator(string OriginalSearchQueryString, QueryExpression QueryPointer)
    {
        if (null != QueryPointer.Criteria)
        {
            //Change the default 'BeginsWith'Operator to 'Contains/Like' operator in the basic search query
            foreach (FilterExpression FilterSet in QueryPointer.Criteria.Filters)
            {
                foreach (ConditionExpression ConditionSet in FilterSet.Conditions)
                {
                    if (ConditionSet.Operator == ConditionOperator.Like)
                    {
                        if (OriginalSearchQueryString != "")
                            ConditionSet.Values[0] = OriginalSearchQueryString;
                        else
                        {
                            OriginalSearchQueryString = QueryPointer.Criteria.Filters[0].Conditions[0].Values[0].ToString();
                            OriginalSearchQueryString = String.Format(CultureInfo.CurrentCulture,
                                             "{0}{1}", LIKE, OriginalSearchQueryString);
                            ConditionSet.Values[0] = OriginalSearchQueryString;
                        }
                    }
                }
            }
        }
        return OriginalSearchQueryString;
    }

Register this plugin as below:

Message: RetrieveMultiple

Primary Entity: none

Secondary Entity: none

Eventing Pipleine Stage of Execution: Pre-Operation

Execution Mode:Synchronous



来源:https://stackoverflow.com/questions/34400873/crm-2011-quick-find-search-using-default-wildcard-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!