Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Post image with FetchXML

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
    Preeti Sharma 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
    Preeti Sharma 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
    Stuie 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
    Preeti Sharma 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
    Stuie 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
    ashlega 34,475 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
    Stuie 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
    ashlega 34,475 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
    Stuie 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
    ashlega 34,475 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

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