Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Retrieve EntityRerence from an AliasedValue and convert that to a string - FetchXML

Posted on by 255

Hi

I'm retrieving data using FetchXML but I'm struggling to check for the AliasValues, retrieve them and then make them strings for insertion in a SQLserver db.

I have it working for non Alias values as below;

if (c.Attributes.Contains("tri_school1type")){
        gSchoolType1 = c.GetAttributeValue<EntityReference>("tri_school1type").Id;
                }
gSchoolType1 is declared as a Guid then i convert out of the fetch loop to a string with;

var sSchoolType1Guid = gSchoolType1;
string sSchoolType1String = sSchoolType1Guid.ToString();


Many thanks

*This post is locked for comments

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Retrieve EntityRerence from an AliasedValue and convert that to a string - FetchXML

    Also it would be good to close thread you opened earlier - community.dynamics.com/.../265357

    Take a minute, open it and mark answers - I'm pretty sure there were such replies.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Retrieve EntityRerence from an AliasedValue and convert that to a string - FetchXML

    Hello,

    Try something like:

    Guid id = ((EntityReference)c.GetAttributeValue<AliasedValue>("aliasname").Value).Id;

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Retrieve EntityRerence from an AliasedValue and convert that to a string - FetchXML

    Should be more or less like this:

    object oVal = ((AliasedValue)c.Attributes["alias.attribute"]).Value;

    Guid id= ((EntityReference) oVal).Id;

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