locked
fetchXML code not working to display in subgrid (what am I doing wrong???) RRS feed

  • Question

  • Dear users, I can't seem to get the below code to work. Would someone be able to see where am I going wrong with this????

    I can have 2 accounts, Parent and Subsidiary(links to parent) and on account entity I have subgrid to add Account Strategy. When I create account strategy on my parent account I want that account strategy to show up in my subgrid under my subsidiary account.

    I have the below code but it doesn't seem to work and I can't figure out where am I going wrong here. Please any help would very much be appreciated! Thanks so much

    function displayAccountStrategy() {
    // This script displays account strategies from the current account and its parent account.
    // It creates a new fetch XML and replaces the fetch XML in the Account Strategy subgrid

         var accountsGrid = document.getElementById("AccountStrategy"); //grid to filter
         if (accountsGrid == null) { //make sure the grid has loaded
             setTimeout(function () { displayAccountStrategy(); }, 2000); //if the grid hasn’t loaded run this again when it has
             return;
         }
     
     // get parent account information
        var parentAccountValue = Xrm.Page.getAttribute("parentaccountid").getValue(); //field to filter by
     
        var parentAccountId = "00000000-0000-0000-0000-000000000000"; //if filter field is null display nothing
         if (parentAccountValue != null) {
             parentAccountId = parentAccountValue[0].id;
         }
     
     // get current account information
     var accountValue = Xrm.Page.getAttribute("name").getValue(); //field to filter by
     
        var accountId = "00000000-0000-0000-0000-000000000000"; //if filter field is null display nothing
         if (accountValue != null) {
             accountId = accountValue[0].id;
         }
     
        //fetch xml code which will retrieve all the accounts related to the contact
         var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
     "<entity name='sp_accountplan'>" +

      "<attribute name='sp_description' />" +
      "<attribute name='ownerid' />" +
      "<attribute name='sp_docstatus' />" +
      "<attribute name='sp_clientid' />" +
      "<attribute name='sp_strategyyear' />" +
      "<attribute name='sp_accountplanId' />" +


      "<order attribute='sp_description' descending='true' />"
      "<filter type='and'>" +
      "<condition attribute='statecode' operator='eq' value='0' />" +
      "<filter type='or'>"
       "<condition attribute='sp_clientid' operator='eq' uiname='" + parentAccountValue + "' uitype='account' value='{" + parentAccountId + "}' />"+
       "<condition attribute='sp_clientid' operator='eq' uiname='" + accountValue + "' uitype='account' value='{" + accountId + "}' />" +
      "</filter>" +
      "</filter>" +
     "</entity>" +
     "</fetch>"
     
        accountsGrid.control.SetParameter("AccountStrategy", fetchXml); //set the fetch xml to the sub grid  
        accountsGrid.control.refresh(); //refresh the sub grid using the new fetch xml

    Friday, December 13, 2013 10:21 PM

All replies

  • *bump*
    Sunday, December 15, 2013 3:58 AM
  • one last try...would anyone mind stabbing to take a look where am i going wrong here??? I cant figure out why is it not working!
    Monday, December 16, 2013 7:03 PM
  • Did you step through using the Dev Tools? Unsupported obviously but I know the SetParameter method changed case at about UR9 2011
    Monday, December 16, 2013 9:19 PM
  • Hi Chris, no I did not use Dev Tools, but more put it together from various tutorials... I found that for UR12 SetParameter has to be labeled with Capital "S"  which I did.. Otherwise, nothing seems to happen on my subgrid and I am not sure if I am just setting this up incorrectly..

    Monday, December 16, 2013 10:32 PM
  • Hi,

    the same problem I hade once. The problem was due to the fetchXML, because it did not return any result.

    Pls let the curly braces off at this line (marked in bold):

    "<condition attribute='sp_clientid' operator='eq' uiname='" + parentAccountValue + "' uitype='account' value='{" + parentAccountId + "}' />"+

    I think your columns are set to the subgrid. Or not? Try it without the curly braces.

    Regards, Karan

    Tuesday, December 17, 2013 9:50 AM
  • Following should be changed :

     accountsGrid.control.SetParameter("AccountStrategy", fetchXml); 

    to:

    accountsGrid.control.SetParameter("fetchXml", fetchXml); 

    More here:

    http://srmscrm.wordpress.com/2012/11/05/changing-the-subgrid-fetchxml-in-ms-crm-2011/

    Thanks

    Sunday, December 22, 2013 2:28 PM