简体   繁体   中英

How can i get the active list in a subgrid in Dynamics CRM using javascript?

What is the javascript code to get the active list which is being shown in a subgrid if the subgrid is designed to show more than one list in the Additional options with the view selector.

What I am trying to achieve is regarding to the list that has been selected in the subgrid I want to assign a new fetchXML value in Javascript.

var grid = parent.document.getElementById("mySubGrid");
// my subgrid has more than one list so I need to get the active list
// if (activeList=="all_elements") {fetchxml=activeListXML} else 
// {fetchxml=anotherXML}
grid.control.SetParameter("fetchXML", fetchXml);

Thanks in advance for your help

I noticed that you are trying to use getElementById ; this is not supported for client-side JavaScript. Instead there is a custom API that you should use

You can get a Grid Control's current view using the following

// Remember when configuring this webresource to enable passing Execution Context
function myCustomGridAction(executionContext) 
{
  // Use executionContext to retrieve FormContext
  var formContext = executionContext.getFormContext();

  // use the formContext to access the particular Grid
  var gridContext = formContext.getControl("myGridId");

  // use the gridContext to get the current View
  var viewSelector = gridContext.getViewSelector();

  // use the viewSelector to get the current view
  var view = viewSelector.getCurrentView();

  // view contains the following properties
  // the View's object type code (Saved Query = 1039) or (User Query (4230)
  console.log(view.entityType);

  // the ID of the view
  console.log(view.id);

  // the Name of the view
  console.log(view.name)
}

More information is here

NOTE : If the subgrid control is not configured to display the view selector, calling this method on the viewSelector object will throw an error.

If you want the XML that the view is using the approach is slightly different

// Remember when configuring this webresource to enable passing Execution Context
function myCustomGridAction(executionContext) 
{
  // Use executionContext to retrieve FormContext
  var formContext = executionContext.getFormContext();

  // use the formContext to access the particular Grid
  var gridContext = formContext.getControl("myGridId");

  // get the XML used to query records displayed in Grid
  var xml = gridContext.getFetchXml();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM