Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Post image with FetchXML

(0) ShareShare
ReportReport
Posted on by 255

Hi

I'm using FetchXML in a CRM online plugin.

Do I need a post image when using FetchXML?

Note I'm using the context.PrimaryEntityId to id the record I want so don't think I need a pre image for that part.

*This post is locked for comments

  • Verified answer
    Preeti Sharma Profile Picture
    2,678 on at
    RE: Post image with FetchXML

    If sCountry is guid type field then please try as below:

    EntityReference country=c.GetAttributeValue<EntityReference>("tri_country");

    sCountry=country.id;

    Hope this helps:)

  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at
    RE: Post image with FetchXML

    Hi,

    Can you please try to get guid as follow:

    sCountry = c.GetAttributeValue<EntityReference>("tri_country");

    Guid country=sCountry.id;

  • Stuie Profile Picture
    255 on at
    RE: Post image with FetchXML

    Hi and thanks

    That seems to give the same result "Microsoft.Xrm.Sdk.EntityReference"

  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at
    RE: Post image with FetchXML

    Hi,

    If you are trying to get guid then i guess you are missing following code:

    sCountry=c.GetAttributeValue<EntityReference>("tri_country").id.ToString();

    Hope this helps:)

  • Stuie Profile Picture
    255 on at
    RE: Post image with FetchXML

    Hi again!

    Ive now got the data coming from the FetchXML and can see it in debug and its inserting into my external SQLserevr db. Happy days.

    But, I have a problem with EntityReferences.
    They are ending up in my db as "Microsoft.Xrm.Sdk.EntityReference"

    I think i need to convert to strings so I can store a value like "8F3E4A08-1263-E611-80C0-308D99276D29" ??

    An example of my code for a guid is;

    sCountry = c.GetAttributeValue<EntityReference>("tri_country").ToString();

    Many thanks

  • Verified answer
    ashlega Profile Picture
    34,477 on at
    RE: Post image with FetchXML

    Hi Stuie,

     don't look at the count - check if you code is entering the loop. Depending on when you are looking at the count, it can be 0 or not.. The query is not, really, executed until you enter "foreach"..

     Enother option might be to try var entityList = results.Entities.ToList(); There you will have the count.

  • Stuie Profile Picture
    255 on at
    RE: Post image with FetchXML

    Hi again

    Thanks for all the help.

    I'm not getting any plugin errors anymore. It seems to run fine.
    The XML I'm using for the fetch tests ok in the online testing tool against our CRM.

    The problem now, even though the testing tool returns data, is all the variables I'm populating from the results are blank! I'm using hard coded xml in terms of the condition to be sure I replicate the test.
    When debugging I can see that the loop shows a count of Zero entities.
    That cannot be correct can it? foreach (var c in results.Entities) <- this = 0

    Why would that be and why would all the values be blank even though  I'm 100% sure there is data.

    Many thanks

  • ashlega Profile Picture
    34,477 on at
    RE: Post image with FetchXML

    Have a look at this:

    community.dynamics.com/.../beware-the-aliasedvalue-attribute-dynamics-crm

    (Scroll down to the bottom - there is sample code)

  • Stuie Profile Picture
    255 on at
    RE: Post image with FetchXML

    Thank you

    I think I've managed to do it using

    sAppID = c.GetAttributeValue<string>("tri_studyapplicationid");

    Just need to figure the same method now for Alias records from Linked Entities -_-

  • ashlega Profile Picture
    34,477 on at
    RE: Post image with FetchXML

    You just need to add a condition - use entity.Contains("attributeName") to check if an attribute is present in the entity (it won't be there if it's null)

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans