SBX - Search With Button

SBX - Forum Post Title

Search Query Issue

Microsoft Dynamics CRM Forum

PeteN asked a question on 18 May 2019 4:57 AM
My Badges

Question Status

Suggested Answer

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>

Reply
Suggested Answer

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")

Reply
Suggested Answer

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.

Reply
Suggested Answer

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 .

Reply
Suggested Answer

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")

Reply
Suggested Answer

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.

Reply
Suggested Answer

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 .

Reply

SBX - Two Col Forum

SBX - Migrated JS