Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Search Query Issue

Posted on by 1,695

CRM2016 On Premises

I have a custom entity new_transactionsets . Account has a 1:N relationship to new_transactionsets (new_licenceid)

I am trying to run a Querybyexpression on new_transactionsets

           Dim SearchQuery As QueryExpression = New QueryExpression("new_transactionsets")
            SearchQuery.ColumnSet = New ColumnSet("new_serialnumber", "new_submissionvalue", "new_noitems")
            SearchQuery.Criteria.FilterOperator = LogicalOperator.And
            SearchQuery.Criteria.AddCondition("new_transactionsetsid", ConditionOperator.Equal, context.PrimaryEntityId.ToString)
            Dim LinkEntityB As LinkEntity = New LinkEntity() With
                {
                .LinkFromEntityName = "new_transactionsets",
                .LinkToEntityName = "account",
                .LinkFromAttributeName = "new_licenceid",
                .LinkToAttributeName = "accountid",
                .JoinOperator = JoinOperator.LeftOuter,
                .Columns = New ColumnSet("name"),
                .EntityAlias = "B"
                }
            LinkEntityB.LinkCriteria.AddCondition("accountid", ConditionOperator.Equal, "new_licenceid")

            SearchQuery.LinkEntities.Add(LinkEntityB)

            Dim SearchQueryCollection As EntityCollection = service.RetrieveMultiple(SearchQuery)
            If SearchQueryCollection.Entities.Count > 0 Then

                For Each _returnedresult In SearchQueryCollection.Entities
                    _serialnumber = _returnedresult.Attributes("new_serialnumber").ToString
                    _licencenumber = _returnedresult.Attributes("name").ToString
                    _submissionvalue = _returnedresult.Attributes("new_submissionvalue").ToString
                    _itemcount = _returnedresult.Attributes("new_noitems").ToString
                    Exit For
                Next
' Write out for testing
                WriteToErrorLog("_serialnumber " & _serialnumber.ToString)
                WriteToErrorLog("_licencenumber " & _licencenumber.ToString)
                WriteToErrorLog("_submissionvalue " & _submissionvalue.ToString)
                WriteToErrorLog("_itemcount " & _itemcount.ToString)

            Else
                WriteToErrorLog("SearchQuery returned no records")
            End If


I am getting the following error 

    <Message>An exception System.FormatException was thrown while trying to convert input value 'new_licenceid' to attribute 'account.accountid'. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).</Message>

*This post is locked for comments

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Search Query Issue

    Below line causing the problem -

               LinkEntityB.LinkCriteria.AddCondition("accountid", ConditionOperator.Equal, "new_licenceid")

    In above line condition  query expected some value of accountid instead of link entity field name(new_licenceid).

    It's should be look like below-

               LinkEntityB.LinkCriteria.AddCondition("accountid", ConditionOperator.Equal, " put some account GUID type value ");

    In addition I would suggest try to build your query using a console application so that you can quickly debug and check which line causing issue .

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    Kalpavruksh D365 CoE 2,545 on at
    RE: Search Query Issue

    Hi,

    It seems that the field new_licenseid is null. We are assuming that "new_licenseid" is the lookup of an account in new_transactionsets entity. Please run this query expression only if new_licenseid has value. If you will share full source code with the expected logic, we will be able to help in resolving this issue.

    Please mark this answer as verified, if it has helped you.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Search Query Issue

    Hi

    Please remove the following line from your code and try again and see if you are still getting the error. You do not need this additional link criteria.

    LinkEntityB.LinkCriteria.AddCondition("accountid", ConditionOperator.Equal, "new_licenceid")

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans