locked
Fetch XML with parameters RRS feed

  • Question

  • I have the following fetch xml that i want to paramatise the licence ie uniname="@Licenceno".

    what do i need to do to allow this with the below fetch xml

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="new_facilitiesmanagementprofiles">
        <attribute name="new_facilitiesmanagementprofilesid" />
        <attribute name="new_sortcode" />
        <attribute name="new_licence" />
        <attribute name="new_accountnumber" />
        <attribute name="new_deposit" />
        <order attribute="new_sortcode" descending="false" />
        <filter type="and">
          <condition attribute="new_licence" operator="eq" uiname="217566" uitype="account" value="{FB0654BB-A208-E311-94E8-00155D01D303}" />
        </filter>
        <link-entity name="account" from="accountid" to="new_licence" visible="false" link-type="outer" alias="a_1747fb7a9212e31194e800155d01d303">
          <attribute name="new_companyname" />
        </link-entity>
      </entity>
    </fetch>


    Dont ask me .. i dont know

    Tuesday, September 17, 2013 10:26 AM

Answers

  • Hi,

    The way of parameterising the fetch xml query depends on the way it is used. Irrespective of the place of usage (Javascript or .NetCode), we need the id of the licence record i.e. Guid of Licence record corresponding to uiname "@Licenceno". 

    1. In case of JSscipt,

    i. If the id of the licence is obtained from Xrm,Page function, it will prefixed by { and postfixed by }.

    In this scenario, use the following:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="new_facilitiesmanagementprofiles">
        <attribute name="new_facilitiesmanagementprofilesid" />
        <attribute name="new_sortcode" />
        <attribute name="new_licence" />
        <attribute name="new_accountnumber" />
        <attribute name="new_deposit" />
        <order attribute="new_sortcode" descending="false" />
        <filter type="and">
          <condition attribute="new_licence" operator="eq" uitype="account" value="+ licenceGuidValue+" />
        </filter>
        <link-entity name="account" from="accountid" to="new_licence" visible="false" link-type="outer" alias="a_1">
          <attribute name="new_companyname" />
        </link-entity>
      </entity>
    </fetch>

    ii. Incase the guid is obtained from callback function, it won't be prefixed or postfixed by { and } respectively. 

    Replace the following line 

    <condition attribute="new_licence" operator="eq" uitype="account" value="+ licenceGuidValue+" />

    by 

    <condition attribute="new_licence" operator="eq" uitype="account" value={"+ licenceGuidValue+"} />

    2. Incase of .Net Code, use the following

    <condition attribute="new_licence" operator="eq" uitype="account" value={0} />

    Also the entire fetch xml string is prefixed with @" and postfixed by "

    The value of guid will be passed in the message . Please use String.Format to format the xml string writing .NetCode(plugin)

    Kind Regards,

    Rameshwari

    • Proposed as answer by RameshwariSah Tuesday, September 17, 2013 6:13 PM
    • Marked as answer by Pete Newman Wednesday, September 18, 2013 8:34 PM
    Tuesday, September 17, 2013 6:13 PM

All replies

  • <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="new_facilitiesmanagementprofiles">
        <attribute name="new_facilitiesmanagementprofilesid" />
        <attribute name="new_sortcode" />
        <attribute name="new_licence" />
        <attribute name="new_accountnumber" />
        <attribute name="new_deposit" />
        <order attribute="new_sortcode" descending="false" />
        <filter type="and">
          <condition attribute="new_licence" operator="eq" uiname="217566" uitype="account" value="@Licenceno" />
        </filter>
        <link-entity name="account" from="accountid" to="new_licence" visible="false" link-type="outer" alias="a_1747fb7a9212e31194e800155d01d303">
          <attribute name="new_companyname" />
        </link-entity>
      </entity>
    </fetch>
    but your parameter should have value is Guid and label is text
    Tuesday, September 17, 2013 11:02 AM
  • Try this

     <condition attribute="new_licence" operator="eq" uiname="@Licenceno" uitype="account"/>


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Proposed as answer by HIMBAPModerator Wednesday, September 18, 2013 6:33 AM
    Tuesday, September 17, 2013 11:23 AM
    Moderator
  • <condition attribute="new_licence" operator="eq" uitype="account" value="@Licenceno" />
    OR

    var LicenceNo = Licenceno;

    <condition attribute="new_licence" operator="eq" uitype="account" value='"+LicenceNo +"' />



    Regards Faisal


    • Edited by Faisal Fiaz Tuesday, September 17, 2013 1:11 PM
    • Proposed as answer by HIMBAPModerator Wednesday, September 18, 2013 6:33 AM
    Tuesday, September 17, 2013 1:08 PM
  • Hi ,

    you just need to pass your value dynamic or static

      *  if you are trying to insert your value static means  Try like bellow

     <condition attribute="new_licence" operator="eq" value="@Licenceno" />

      * If you are tring to pass your value dynamic means  Try Like Bellow Code  

        <condition attribute="new_licence" operator="eq" value='"+Licenceno+"' />

    Sample Linkhttp://guruprasadcrm.blogspot.in/2011/06/executing-fetchxml-in-crm-2011.html

    ----------------------------------

     You can also use query string method, [ as i prefer , Itz easy compared to Fetch XML ]

    Tuesday, September 17, 2013 1:38 PM
  • Hi,

    The way of parameterising the fetch xml query depends on the way it is used. Irrespective of the place of usage (Javascript or .NetCode), we need the id of the licence record i.e. Guid of Licence record corresponding to uiname "@Licenceno". 

    1. In case of JSscipt,

    i. If the id of the licence is obtained from Xrm,Page function, it will prefixed by { and postfixed by }.

    In this scenario, use the following:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="new_facilitiesmanagementprofiles">
        <attribute name="new_facilitiesmanagementprofilesid" />
        <attribute name="new_sortcode" />
        <attribute name="new_licence" />
        <attribute name="new_accountnumber" />
        <attribute name="new_deposit" />
        <order attribute="new_sortcode" descending="false" />
        <filter type="and">
          <condition attribute="new_licence" operator="eq" uitype="account" value="+ licenceGuidValue+" />
        </filter>
        <link-entity name="account" from="accountid" to="new_licence" visible="false" link-type="outer" alias="a_1">
          <attribute name="new_companyname" />
        </link-entity>
      </entity>
    </fetch>

    ii. Incase the guid is obtained from callback function, it won't be prefixed or postfixed by { and } respectively. 

    Replace the following line 

    <condition attribute="new_licence" operator="eq" uitype="account" value="+ licenceGuidValue+" />

    by 

    <condition attribute="new_licence" operator="eq" uitype="account" value={"+ licenceGuidValue+"} />

    2. Incase of .Net Code, use the following

    <condition attribute="new_licence" operator="eq" uitype="account" value={0} />

    Also the entire fetch xml string is prefixed with @" and postfixed by "

    The value of guid will be passed in the message . Please use String.Format to format the xml string writing .NetCode(plugin)

    Kind Regards,

    Rameshwari

    • Proposed as answer by RameshwariSah Tuesday, September 17, 2013 6:13 PM
    • Marked as answer by Pete Newman Wednesday, September 18, 2013 8:34 PM
    Tuesday, September 17, 2013 6:13 PM