Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Query by Expression

Posted on by 1,695

CRM2016 On Premises

Firstly thank you for all the help on this linked query.

I am trying to get the new_licenceid value to a string ( to pass through to a workflow ) . New_licenceid is a 1:N relationship from accounts .

I have tried several different ways to get the id but all get is Conversion from type 'EntityReference' to type 'String' is not valid.

help

                    Dim SearchQuery As QueryExpression = New QueryExpression("new_transactionsets")
                    SearchQuery.ColumnSet = New ColumnSet("new_transactionsetsid", "new_licenceid")
                    SearchQuery.Criteria.FilterOperator = LogicalOperator.And
                    SearchQuery.Criteria.AddCondition("new_fileserial", ConditionOperator.EndsWith, _str_serialnumber)
                    SearchQuery.Criteria.AddCondition("new_creditdebitdate", ConditionOperator.Equal, _clearedfundsdate)
                    SearchQuery.Criteria.AddCondition("new_transactioncount", ConditionOperator.Equal, _fileCount)
                    SearchQuery.Criteria.AddCondition("new_submissionvalue", ConditionOperator.Equal, _fileTotal)
                    Dim linkEntityB As LinkEntity = New LinkEntity() With {
        .LinkFromEntityName = "new_transactionsets",
        .LinkFromAttributeName = "new_originatingaccount",
        .LinkToEntityName = "new_originatingaccounts",
        .LinkToAttributeName = "new_originatingaccountsid",
        .JoinOperator = JoinOperator.LeftOuter,
        .Columns = New ColumnSet("new_sun"),
        .EntityAlias = "B"}
                    linkEntityB.LinkCriteria.AddCondition("new_sun", ConditionOperator.Equal, _sun)
                    Dim TransactionSetCollection As EntityCollection = service.RetrieveMultiple(SearchQuery)


                    If TransactionSetCollection.Entities.Count > 0 Then

                        For Each _tset In TransactionSetCollection.Entities
                            Using sw As StreamWriter = File.AppendText(Globals.clsGlobals.LogFile & "importer.txt")
                                sw.WriteLine("TEST new_licenceid " & CType(_tset.Attributes("new_licenceid"), String))
                            End Using
                        Next
                    End If


*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Query by Expression

    Hi Pete,

    You can get guid from the entity reference as below:

    foreach (Entity _tset in TransactionSetCollection.Entities)

               {

                   string guidLicence = string.Empty;

                   if (_tset .Contains("new_licenceid"))

                       guidLicence = _tset .GetAttributeValue<EntityReference>("new_licenceid").Id.ToString();

               }

    Hope this helps!

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans