• Resolved andreaspsson

    (@andreaspsson)


    Hi,

    I cannot really figure out how to use the fetch xml query tag in the twig templates, quite new to everything related to WordPress, so it can be just me misunderstanding the documentation, but I cannot get my head around it.

    Anyhow, I have connected the plugin to the CRM and when a try to list accounts using the view tag like the example below everything works great:

    
    [msdyncrm_twig]
      {% view entity="account" name="Active Accounts" count="10" cache="PT30M" %}
        <h3>DATA - list the fetched records</h3>
        <div>
          {% for c in entityview.records %}
            <li>{{ c.name }} - {{c.modifiedon}}</li>
          {% endfor %} 
        </div>
      {% endview %}
    
    [/msdyncrm_twig]
    

    But when I try to do the same thing using the fetch xml tag I get no results, nothing is rendered, as far a I can tell the variable accounts in the example below does not even exist. The xml I just downloaded from the advanced search dialog in Dynamics after selecting the same view as in te example above (“Active accounts”)

    
    [msdyncrm_twig]
      {% fetchxml collection="accounts" %}
        <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
          <entity name="account">
            <attribute name="name" />
            <attribute name="new_companyname" />
            <attribute name="primarycontactid" />
            <attribute name="modifiedon" />
            <attribute name="new_syncstate" />
            <attribute name="new_recordid" />
            <attribute name="accountnumber" />
            <attribute name="accountid" />
            <order descending="true" attribute="modifiedon" />
            <filter type="and">
              <condition attribute="statecode" operator="eq" value="0" />
            </filter>
            <link-entity name="contact" from="contactid" to="primarycontactid" visible="false" link-type="outer" alias="a_410707b195544cd984376608b1802904">
              <attribute name="emailaddress1" />
              <attribute name="telephone1" />
            </link-entity>
          </entity>
        </fetch>
      {% endfetchxml %}
    
      <div>
        <h3>RESULTS:</h3>
        <p>error?: {{accounts.error}}</p>
        <ul>
          {% for a in accounts.results.entities %}
            <li>{{a.name}}</li>
          {% endfor %}
        </ul>
      </div>
    [/msdyncrm_twig]
    

    Am I missing something in the syntax here? Or what to look for? Or what to try, anyone have any hints?

    //Andreas

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author alexacrm

    (@alexacrm)

    Andreas,

    syntax is correct and when I test your fetchxml (without custom columns, of course), it does return data. Perhaps caching is at play, try flushing cache on Connection tab of the plugin.

    If it still does not work, take fetchxml and use fetchxml builder plugin in https://www.xrmtoolbox.com to test your fetch and confirm that it does return data.

    Thanks
    George

    Thread Starter andreaspsson

    (@andreaspsson)

    Ok,

    I tried to flush the cache, I guess you meant by pressing the button “Regenerate Metadata Cache”, that did not make any difference, still no data.

    Running the query in xrmtoolbox works great, then I get the response I expect for the query.

    Looked into the plugin logs (changed to debug verbosity in the plugin settings), there I can see that if I run my working example I get big payloads with soap request data in the log, example:

    
    [2022-02-10 09:15:58] wpcrm.DEBUG: Registered 11 shortcode handlers. {"shortcodes":["view","field","form","twig","inline","crm_login","login","registration","change_password","invitation","user"]} []
    [2022-02-10 09:15:58] wpcrm.INFO: Rendering shortcode [msdyncrm_twig]. [] []
    [2022-02-10 09:15:58] wpcrm.INFO: Rendering shortcode [msdyncrm_twig]. [] []
    [2022-02-10 09:16:01] crmtoolkit.DEBUG: Executed a SOAP request in 2.75882601738 seconds {"request":"<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\
    ...
    ...
    ...
    

    But if I run the fetch xml example there are no soap requests in the log, just this:

    
    [2022-02-10 11:21:22] wpcrm.DEBUG: Initializing Dynamics 365 Integration. [] []
    [2022-02-10 11:21:22] wpcrm.DEBUG: Initializing PHP CRM Toolkit. [] []
    [2022-02-10 11:21:22] wpcrm.DEBUG: Initializing cache. [] []
    [2022-02-10 11:21:22] crmtoolkit.DEBUG: cURL version {"curlVersion":{"version_number":477696,"age":7,"features":29345693,"ssl_version_number":0,"version":"7.74.0","host":"x86_64-pc-linux-gnu","ssl_version":"OpenSSL/1.1.1k","libz_version":"1.2.11","protocols":["dict","file","ftp","ftps","gopher","http","https","imap","imaps","ldap","ldaps","mqtt","pop3","pop3s","rtmp","rtsp","scp","sftp","smb","smbs","smtp","smtps","telnet","tftp"],"ares":"","ares_num":0,"libidn":"2.3.0","iconv_ver_num":0,"libssh_version":"libssh2/1.9.0","brotli_ver_num":16777225,"brotli_version":"1.0.9"},"tls_constants":{"CURL_SSLVERSION_TLSv1_2":true}} []
    [2022-02-10 11:21:22] wpcrm.DEBUG: Finished initializing PHP CRM Toolkit. [] []
    [2022-02-10 11:21:22] wpcrm.DEBUG: Initializing PHP CRM Toolkit Metadata storage. [] []
    [2022-02-10 11:21:22] wpcrm.DEBUG: Initializing storage <metadata>. [] []
    [2022-02-10 11:21:22] wpcrm.DEBUG: Initializing storage <images>. [] []
    [2022-02-10 11:21:22] wpcrm.DEBUG: Initializing shortcodes. [] []
    [2022-02-10 11:21:22] wpcrm.DEBUG: Registered 11 shortcode handlers. {"shortcodes":["view","field","form","twig","inline","crm_login","login","registration","change_password","invitation","user"]} []
    [2022-02-10 11:21:23] wpcrm.INFO: Rendering shortcode [msdyncrm_twig]. [] []
    [2022-02-10 11:21:27] wpcrm.DEBUG: Initializing Dynamics 365 Integration. [] []
    [2022-02-10 11:21:27] wpcrm.DEBUG: Initializing PHP CRM Toolkit. [] []
    [2022-02-10 11:21:27] wpcrm.DEBUG: Initializing cache. [] []
    [2022-02-10 11:21:27] crmtoolkit.DEBUG: cURL version {"curlVersion":{"version_number":477696,"age":7,"features":29345693,"ssl_version_number":0,"version":"7.74.0","host":"x86_64-pc-linux-gnu","ssl_version":"OpenSSL/1.1.1k","libz_version":"1.2.11","protocols":["dict","file","ftp","ftps","gopher","http","https","imap","imaps","ldap","ldaps","mqtt","pop3","pop3s","rtmp","rtsp","scp","sftp","smb","smbs","smtp","smtps","telnet","tftp"],"ares":"","ares_num":0,"libidn":"2.3.0","iconv_ver_num":0,"libssh_version":"libssh2/1.9.0","brotli_ver_num":16777225,"brotli_version":"1.0.9"},"tls_constants":{"CURL_SSLVERSION_TLSv1_2":true}} []
    [2022-02-10 11:21:27] wpcrm.DEBUG: Finished initializing PHP CRM Toolkit. [] []
    [2022-02-10 11:21:27] wpcrm.DEBUG: Initializing PHP CRM Toolkit Metadata storage. [] []
    [2022-02-10 11:21:27] wpcrm.DEBUG: Initializing storage <metadata>. [] []
    [2022-02-10 11:21:27] wpcrm.DEBUG: Initializing storage <images>. [] []
    [2022-02-10 11:21:27] wpcrm.DEBUG: Initializing admin UI. [] []
    

    Is that expected?

    I run version 1.3.2 of the plugin.

    //Andreas

    • This reply was modified 4 years, 4 months ago by andreaspsson.
    • This reply was modified 4 years, 4 months ago by andreaspsson.
    Plugin Author alexacrm

    (@alexacrm)

    Your second fetch does not run at all – that’s why no results.

    I don’t know why – it works in my settings.
    Try stripping out linked entity and get down to the simplest fetch for accounts – see if that works.

    [msdyncrm_twig]
      {% fetchxml collection="accounts" %}
        <fetch distinct='false' count='10'>
          <entity name="account">
            <attribute name="name" />
          </entity>
        </fetch>
      {% endfetchxml %}
    
      <div>
        <h3>RESULTS:</h3>
        <ul>
          {% for a in accounts.results.entities %}
            <li>{{a.name}}</li>
          {% endfor %}
        </ul>
      </div>
    [/msdyncrm_twig]

    Perhaps there is another “accounts” fetch on the same page, perhaps typo, perhaps you have a block or page builder that “swallows” fetchxml (seen this happening as fetchxml includes < and > characters. If it still does not work, please paste the full source for the specific page and we’ll take it from there.

    Thread Starter andreaspsson

    (@andreaspsson)

    Hi,

    You are on to something there! I was only previewing the page since I am only testing right now before building some real stuff. But when I actually save the page and realod the xml is just gone! And if I add the xml to the page directly in the sql database, saving and realoading the page, then it works!

    Any ideas on what may cause this?

    //Andreas

    Plugin Author alexacrm

    (@alexacrm)

    You are probably using HTML block. It detects <> and strips out the content. The workaround is to use a block that does not touch the content. Try shortcode block or custom HTML block. The other thing to do is to surround fetchxml with <!– –> making it HTML comment.

    Actually I’d recommend taking a look at our v.Next plugin: https://ww.wp.xz.cn/plugins/integration-cds. We have special Twig block included that supports syntax highlighting and does not touch code. The plugin is based on Web API and is our primary focus moving forward.

    Thread Starter andreaspsson

    (@andreaspsson)

    Hi!

    I use shortcode blocks, but that does not help, all xml is removed when saved 🙁
    Is the intention that these twigs shall work in shortcode blocks? just some setting on my side that makes the xml disappear?

    Looked into that other plugin you mentioned, but no luck there since it, as far as I could understand, not support on-premises deployments of dynamics.

    //Andreas

    Plugin Author alexacrm

    (@alexacrm)

    Andreas,

    I’m not sure why shortcode block strips out fetchxml – it’s not supposed to touch the content. Try using custom HTML block and if that does not help, try surrounding fetchxml with HTML comments (as twig is processed independently), e.g.

    [msdyncrm_twig]
    <!-- 
      {% fetchxml collection="accounts" %}
        <fetch distinct='false' count='10'>
          <entity name="account">
            <attribute name="name" />
          </entity>
        </fetch>
      {% endfetchxml %}
    -->
      <div>
        <h3>RESULTS:</h3>
        <ul>
          {% for a in accounts.results.entities %}
            <li>{{a.name}}</li>
          {% endfor %}
        </ul>
      </div>
    [/msdyncrm_twig]
    Thread Starter andreaspsson

    (@andreaspsson)

    No, that did not work either. Don’t get it…
    Anyhow, we decided to fetch the data directly using the ASDK()->retrieveMultiple function instead.

    But still if I figure out the problem I will update, so any one else bumping into this may get helped

    Plugin Author alexacrm

    (@alexacrm)

    @andreaspsson something is stripping fetchxml from your page content. Could be a plugin or some settings. There is no way to tell without looking at the system.

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘No results using Fetch XML Query’ is closed to new replies.