web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Query Build Error: The specified field does not exist in Microsoft Dynamics 365

(0) ShareShare
ReportReport
Posted on by

Hi,

My team is working on Microsoft Dynamics 365 online (8.2.1.176).

Recently, we have started to see a issue arise whenever we export our solution, created in a sandbox environment. When we try to Export Solution, at the end of it all it throws the error "Query Build Error: The specified field does not exist in Microsoft Dynamics 365" without giving any additional clues. 

35655.Capture.JPG

This post also talks about the same issue, a possible bug in the system.

As we are working on online version, we are helpless. Looking for assistance.

Regards,

Avinash

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     you can fix it by removing all entities (don't forget to save the solution and publish the changes.. just in case), then re-adding the entities. Not sure if this will work for you (since you may have to choose the assets etc - might be too much work).. but it did fix the problem for me.

  • Community Member Profile Picture
    on at

    That's a good thought. Thanks.

    But we have a lot of entities and assets, it is going to take a while.

    Any other solutions? Please help.

  • Community Member Profile Picture
    on at

    When you have problem you need to go through the pain. There's no shortcut =D

  • Kjeld Poulsen Profile Picture
    180 on at

    If you are not afraid of C# code and SDK usage, this piece of code will do the trick:

    Basically what it does is, lookup up the solution, and after that all components in the solution. Then it is lookup up

    all entities and related attributes in the system, and finally run through all attributes in the solution, and if not found, it removes

    the field from the solution.

    public void FindMissingField()
    {
    var sol = (from s in uow.Solutions.GetQuery() where s.FriendlyName == "mysolutionname" select s).Single();
    var components = (from p in uow.SolutionComponents.GetQuery()
    where p.SolutionId.Id == sol.SolutionId.Value
    select p).ToArray();

    var meta = new Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesRequest
    {
    EntityFilters = Microsoft.Xrm.Sdk.Metadata.EntityFilters.Attributes,
    RetrieveAsIfPublished = true
    };

    var result = uow.ExecuteRequest<Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesResponse>(meta);
    var attributes = new Dictionary<Guid, Microsoft.Xrm.Sdk.Metadata.AttributeMetadata>();

    foreach (var entity in result.EntityMetadata)
    {
    foreach (var attr in entity.Attributes)
    {
    attributes[attr.MetadataId.Value] = attr;
    }
    }


    foreach (var component in components)
    {
    if (component.ComponentType.Value == ((int)Entities.SolutionComponent.ComponentTypeEnum.Attribute))
    {
    if (!attributes.ContainsKey(component.ObjectId.Value))
    {
    Console.WriteLine("Not found " + component.LogicalName);
    var removeRequest = new RemoveSolutionComponentRequest
    {
    SolutionUniqueName = sol.UniqueName,
    ComponentId = component.ObjectId.Value,
    ComponentType = component.ComponentType.Value
    };

    uow.Execute(removeRequest);
    }
    }
    }
    }

  • Eric benco Profile Picture
    320 on at

    You can run this code from the 'Code Now' plugin in the XrmToolBox (alot easier then firing up Visual Studio)

    HOWEVER, However it wasn't working for CRM OnLine

    // CODE DELETED.  See working solution below.
  • Kjeld Poulsen Profile Picture
    180 on at

    I do like your example because it does show all needed code, and not just the conceptual idear (as mine ex. using a unit of work concept on top of crm sdk generated entities)  but the try catch approach is potentially risky. Other things than an attribute is missing in the system could be the result of the  RetrieveAttributeResponse, ex. SQL Timeout or ...+LogMessage could also throw exception. In such case your code would try to delete the component, even though it actually exists.

  • Suggested answer
    Eric benco Profile Picture
    320 on at

    Here is the correct version that will work with CRM OnLine.    You'll need the XrmToolBox with the "Code Now" plugin to run this.

    /******
    
    XrmToolBox - Code Now - Find and remove invalid attributes -> bettercrm.blog/.../query-builder-error-when-exporting-solution-in-dynamics-365
    Add These to the Using box on the right
    
    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    using Microsoft.Xrm.Sdk.Messages;
    using Microsoft.Crm.Sdk.Messages;
    *******/
    
            public static void CodeNow()
            {
                string SOLUTION_NAME = "PUT_YOUR_SOLUTION_NAME_HERE";
                
                LogMessage("------------- Start -----------------");
                LogMessage("Solution " + SOLUTION_NAME);
    
                var solutionComponentQuery = new QueryExpression("solutioncomponent");
                solutionComponentQuery.Distinct = true;
                solutionComponentQuery.ColumnSet.AddColumns("objectid", "componenttype", "solutioncomponentid");
                var solutioncomponentSolutionLink = solutionComponentQuery.AddLink("solution", "solutionid", "solutionid");
                solutioncomponentSolutionLink.EntityAlias = "aa";
                solutioncomponentSolutionLink.LinkCriteria.AddCondition("uniquename", ConditionOperator.Equal, SOLUTION_NAME);
    
                var results = Service.RetrieveMultiple(solutionComponentQuery);
                foreach (var item in results.Entities)
                {
                    
                    var componentType = item.GetAttributeValue<OptionSetValue>("componenttype").Value;
                    //LogMessage("Checking Component " + componentType);
                    if (componentType == 2)
                    {
                        //LogMessage("Checking Attribute");
                        var attributeRequest = new RetrieveAttributeRequest
                        {
                            MetadataId = item.GetAttributeValue<Guid>("objectid")
                        };
    
                        try
                        {
                            var result = (RetrieveAttributeResponse)Service.Execute(attributeRequest);
                            LogMessage("Attribute " + result.AttributeMetadata.LogicalName + " is valid");
                        }
                        catch
                        {
                            // //attribute is missing, remove it from solution
                            LogMessage("Attribute {" + attributeRequest.MetadataId + "} is missing. Removing from the solution.");
                            
                            var removeRequest = new RemoveSolutionComponentRequest
                            {
                                SolutionUniqueName = SOLUTION_NAME,
                                ComponentId = attributeRequest.MetadataId,
                                ComponentType = componentType
                            };
                            Service.Execute(removeRequest);
                        }
                    }
                }
                LogMessage("----------------------DONE-------------------");
            }
  • julians Profile Picture
    612 Moderator on at

    Eric

    I just had the same issue and used your code and it worked!

    I suspect it was rollup fields that I had deleted 

    Thanks

    Julian

  • Suggested answer
    ObiSenior Profile Picture
    on at

    Worked like a dream!

  • julians Profile Picture
    612 Moderator on at

    I did a quick test. I created a rollup field in a solution and then deleted the field. I got the error when trying to export the solution. I think the state and last time updated fields are still in the solution but they no longer exist.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans