A Place for Sharing and Inspiration

Total Pageviews

Thursday, October 21, 2021

Tip - How to convert a XML file to filters in Advanced Find in Dynamics 365 (CRM)


XML file

For instance, if we’ve already got a XMl file like below,

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">  <entity name="contact">    <attribute name="fullname" />    <attribute name="telephone1" />    <attribute name="contactid" />    <order attribute="fullname" descending="false" />    <filter type="and">      <condition attribute="firstname" operator="eq" value="alex" />      <condition attribute="mobilephone" operator="eq" value="619-555-0129" />    </filter>  </entity></fetch>

Convert the xml file to JavaScript string

Open the xml file using notepad++ or any other text and source code editor that you can get, then follow below steps:

  1. Press Ctrl + A on your keyboard to select the entire script
  2. Press Ctrl + J on your keyboard to change xml to a single string, and then assign it to a variable fetchxml (you can also use other name as long as it meet Naming and declaration rules for variables of JavaScript)
fetchxml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">   <entity name="contact">     <attribute name="fullname" />     <attribute name="telephone1" />     <attribute name="contactid" />     <order attribute="fullname" descending="false" />     <filter type="and">       <condition attribute="firstname" operator="eq" value="alex" />       <condition attribute="mobilephone" operator="eq" value="619-555-0129" />     </filter>   </entity> </fetch>';

Convert JavaScript to filters in Advanced Find

  1. Open Advanced Find, and find the Contact entity (or the entity you’re looking for), then ensure there is no existing filters set up,

image-20211021233801601

  1. Hit F12 on your keyboard
  2. Select the ‘contentIFrame0’ from the dropdown list as the red arrow shown on below snip

image-20211021234555643

  1. Copy the variable and the value into the Console, hit Enter

image-20211021235053383

  1. Enter below magic script into the Console, and hit enter again,

    $find(‘advFind’).set_fetchXml(fetchxml);

image-20211021235213827

Bingo! you will see the filters in Advanced Find accordingly

image-20211021235451476

0 comments:

Post a Comment