web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I'm sorry but it's not clear how do you use it. Can you please provide deeper explanation?

  • Stuie Profile Picture
    255 on at

    Hi

    OK I'm getting data from CRM for a sync with an external system via webservice and to do so I'm using FetchXML from a plugin.

    On a CRM record 'Update' the plugin runs and I use context.PrimaryEntityId to identify the record I need.

    My XML is from the Advanced Filter in CRM and Ive tested the XML in the FetchXML tester that Microsoft provide.

    My problem is I'm getting a NullReference Exception so my question was do I need to have added a Post Image to get the data from via my Plugin?

    I had hoped the XML would be all thats required to extract the data from the CRM database.

    Many thanks

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    I still see no issue. Can you please provide your code?

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    PostImage is just an image of the entity on which your plugin is running. It has nothing to do with whatever you query using Fetch.. the error is likely happening because of something else.

  • Stuie Profile Picture
    255 on at

    OK thanks so theres no need to include an image?

  • ashlega Profile Picture
    34,477 on at

    That's a different question:) Maybe there is, but it would not have anything to do with fetch query.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    For your particular needs that you specified, most likely no need to include your post image.

    The logic below will allow you use fetchXml based on context.PrimaryEntityId

    Guid accountId = context.PrimaryEntityId;

    StringBuilder sb = new StringBuilder();

    sb.AppendLine("<fetch distinct='false' mapping='logical' aggregate='false'> ");

    sb.AppendLine(" <entity name='account'> ");

    sb.AppendLine("  <attribute name='accountnumber' /> ");

    sb.AppendLine("  <attribute name='name' /> ");

    sb.AppendLine("  <filter type='and'>");

    sb.AppendLine("   <condition attribute='accountid' operator='eq' value='" + accountId.ToString() + "' /> ");

    sb.AppendLine("  </filter> ");

    sb.AppendLine(" </entity> ");

    sb.AppendLine("</fetch>");

    FetchExpression fe = new FetchExpression(sb.ToString());

    EntityCollection rc = service.RetrieveMultiple(fe);

    Hope this helps.

  • Stuie Profile Picture
    255 on at

    Hi

    Thanks for the help.

    Still getting a NullException Object reference not set to an instance of an object.
    Seems to happen on the retrievemultiple

                string fetchQuery = @"<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false'>" +
                                "<entity name='tri_studyapplication'>" +
                                "<attribute name='createdon'/>" +
                                "<attribute name='statuscode'/>" +
                                "<attribute name='tri_applicationtype'/>" +
                                "<attribute name='modifiedon'/>" +
                                "<attribute name='ownerid'/>" +
                                "<attribute name='tri_contactid'/>" +
                                "<attribute name='tri_country'/>" +
                                "<attribute name='tri_formstage'/>" +
                                "<attribute name='tri_designation'/>" +
                                "<attribute name='tri_studyapplicationid'/>" +
                                "<attribute name='tri_ucascode'/>" +
                                "<attribute name='tri_school2programme'/>" +
                                "<attribute name='tri_school2name'/>" +
                                "<attribute name='tri_otherschools'/>" +
                                "<attribute name='tri_firstchoice'/>" +
                                "<attribute name='tri_finishdate2'/>" +
                                "<attribute name='tri_finishdate1'/>" +
                                "<attribute name='tri_doc_previouschoolid'/>" +
                                "<attribute name='tri_doc_personalstatementid'/>" +
                                "<attribute name='tri_doc_otherschoolid'/>" +
                                "<attribute name='tri_doc_highschoolcertificateid'/>" +
                                "<attribute name='tri_doc_englishlanguagecertificateid'/>" +
                                "<attribute name='tri_doc_degreecertificatetranslationid'/>" +
                                "<attribute name='tri_doc_degreecertificateid'/>" +
                                "<attribute name='tri_doc_cvid'/>" +
                                "<attribute name='tri_school1programme'/>" +
                                "<attribute name='tri_school1name'/>" +
                                "<attribute name='tri_course1info'/>" +
                                "<attribute name='tri_reference1postalcode'/>" +
                                "<attribute name='tri_reference1position'/>" +
                                "<attribute name='tri_reference1line1'/>" +
                                "<attribute name='tri_reference1lastname'/>" +
                                "<attribute name='tri_reference1firstname'/>" +
                                "<attribute name='tri_reference1email'/>" +
                                "<attribute name='tri_reference1country'/>" +
                                "<attribute name='tri_reference1city'/>" +
                                "<attribute name='tri_startdate2'/>" +
                                "<attribute name='tri_startdate1'/>" +
                                "<attribute name='tri_course2info'/>" +
                                "<attribute name='tri_convictions'/>" +
                                "<attribute name='tri_convictioninfo'/>" +
                                "<attribute name='tri_handicap'/>" +
                                "<attribute name='tri_eucitizen'/>" +
                                "<attribute name='emailaddress'/>" +
                                "<attribute name='tri_reference1telephone'/>" +
                                "<attribute name='tri_reference1stateorprovince'/>" +
                                "<attribute name='tri_school2type'/>" +
                                "<attribute name='tri_school1type'/>" +
                                "<order descending='false' attribute='tri_contactid'/>" +
                                "<filter type='and'>" +
                                "<condition value='xxx@xxxx.com' attribute='emailaddress' operator='eq'/>" +
                                "</filter>" +
                                "<link-entity name='tri_studychoice' to='tri_sixthchoice' from='tri_studychoiceid' visible='false' link-type='outer' alias='a_choice6'>" +
                                "<attribute name='statuscode'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studychoice' to='tri_firstchoice' from='tri_studychoiceid' visible='false' link-type='outer' alias='a_choice1'>" +
                                "<attribute name='statuscode'/>" +
                                "<attribute name='tri_name'/>" +
                                "<attribute name='tri_universityorcollege'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studychoice' to='tri_secondchoice' from='tri_studychoiceid' visible='false' link-type='outer' alias='a_choice2'>" +
                                "<attribute name='statuscode'/>" +
                                "<attribute name='tri_universityorcollege'/>" +
                                "<attribute name='tri_name'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studydocument' alias='a_CV' link-type='outer' visible='false' from='tri_studydocumentid' to='tri_doc_cvid'>" +
                                "<attribute name='tri_name'/>" +
                                "<attribute name='tri_link'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studydocument' alias='a_personalstatement' link-type='outer' visible='false' from='tri_studydocumentid' to='tri_doc_personalstatementid'>" +
                                "<attribute name='tri_name'/>" +
                                "<attribute name='tri_link'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studydocument' alias='a_engtest' link-type='outer' visible='false' from='tri_studydocumentid' to='tri_doc_englishlanguagecertificateid'>" +
                                "<attribute name='tri_name'/>" +
                                "<attribute name='tri_link'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studydocument' alias='a_diploma' link-type='outer' visible='false' from='tri_studydocumentid' to='tri_doc_degreecertificateid'>" +
                                "<attribute name='tri_name'/>" +
                                "<attribute name='tri_link'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studydocument' alias='a_diplomatranslated' link-type='outer' visible='false' from='tri_studydocumentid' to='tri_doc_degreecertificatetranslationid'>" +
                                "<attribute name='tri_name'/>" +
                                "<attribute name='tri_link'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studydocument' alias='a_reference' link-type='outer' visible='false' from='tri_studydocumentid' to='tri_doc_reference1id'>" +
                                "<attribute name='tri_name'/>" +
                                "<attribute name='tri_link'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studydocument' alias='a_prevschoolcert' link-type='outer' visible='false' from='tri_studydocumentid' to='tri_doc_previouschoolid'>" +
                                "<attribute name='tri_name'/>" +
                                "<attribute name='tri_link'/>" +
                                "</link-entity>" +
                                "<link-entity name='tri_studydocument' alias='a_otherschoolcert' link-type='outer' visible='false' from='tri_studydocumentid' to='tri_doc_otherschoolid'>" +
                                "<attribute name='tri_name'/>" +
                                "<attribute name='tri_link'/>" +
                                "</link-entity>" +
                                "</entity>" +
                                "</fetch>";
    
                tracingService.Trace("xml 1 done.");
    
                FetchExpression fe = new FetchExpression(fetchQuery);
                tracingService.Trace("create fetch");
                EntityCollection results = _service.RetrieveMultiple(fe);


  • Stuie Profile Picture
    255 on at

    I've reduced the number of linked entities. The above had too many

  • Suggested answer
    Swetha Poojary Salaskar Profile Picture
    326 on at

    HI Stuie,

    Can you please high light code where are you providing EntityId in above code. And First check if you are getting EntityId in context. ON update message you should get Entity Id in Context and no need to use Images.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans