zoukankan      html  css  js  c++  java
  • get data from grid

    Here are a few useful examples of getting some data from the grid in CRM. I’ve used these in my ISV.config customizations in order to grab certain data that i want to pass to my custom pages. For the most part, a lot of this stuff gets passed automatically when you specify PassParams = 1, but I often have to construct page links dynamically in ISV.config using Javascript, so the PassParams argument does not work.

    First, here’s how to get the Id of the displayed view and the Object Type Code of the records it returns:
    //    get guid and object type code of view being displayed (otc 1039 = savedquery, system view)
    var sViewId = document.all['crmGrid'].GetParameter('viewid');
    var sViewType = document.all['crmGrid'].GetParameter('viewtype');
    You may notice that the code is slightly different from what I’ve presented before. The method above is a more robust way of getting the data, as it also works with the Associated Grids on an entity’s form.
    To get the Object Type Code of the records that are in the grid, use the following:
    var sOtc = document.all['crmGrid'].GetParameter('otc');
    The following snippet will allow you to retrieve an array containing the Id values of the selected records in the grid:
    //    get array of selected records
    var a = document.all['crmGrid'].InnerGrid.SelectedRecords;
    var selectedItems = new Array(a.length);
    for (var i=0; i < a.length; i++)
    {
        selectedItems = a[0];
    }
    alert(selectedItems);
    To get all of the records in the grid (ie. “All Records on Current Page”):
    //    array of all records on current page
    var iTotal = document.all['crmGrid'].InnerGrid.NumberOfRecords;
    var o = document.all['crmGrid'].InnerGrid;
    var allItems = new Array;
    for (var i=0; i < iTotal; i++)
    {
        allItems[i] = o.rows.oid;
      
    }
    alert(allItems);
    If the grid you are working with is displaying records from an Associated View, you can use the following to retrieve the Id and Object Type Code of the main record:
    //    get object id and type code of main record when grid is an associated view
    var oId = document.all['crmGrid'].GetParameter('oId');
    var oType = document.all['crmGrid'].GetParameter('oType');
    For kicks and giggles, here is some code that will retrieve the Grid XML. you can use this for researching other types of properties that are available from the grid object that I have not presented here (and there are a few):
    var gridXml = document.all['crmGrid'].gridXml;
    Bonus Snippet!I’ve seen a bunch of questions on how to retrieve the query used in an Advanced Find that has not yet been saved. Well, here ya go:
    //    Advanced Find fetchXml
    alert(window.top.resultRender.FetchXml.value);
    This piece of code will display the Fetch XML that is used by the Advanced Find to query CRM.

    To make scripts a little bit more readable, it is also possible to use crmGrid object directly instead of document.all['crmGrid']. e.g.:
    crmGrid.InnerGrid.SelectedRecords
    crmGrid.GetParameter("otc")
    crmGrid.Refresh()
  • 相关阅读:
    Excel密码解除方法 破解
    盗刷惊魂:招行银行信用卡被盗刷,亲身经历告诉你怎样快速挽回损失(信用卡网上被盗刷消费爆出潜规则)
    利用webBrowser获取页面iframe中的内容
    Winform 部署mshtml程序集出错的解决方案(该应用程序要求在全局程序集缓存GAC中安装程序集miscrosft.mshtml)
    分时均线最佳买点,分时均线操作法(转)
    Spring.NET学习笔记12——面向切面编程(基础篇) Level 300
    Spring.NET学习笔记18——整合NHibernate(基础篇) Level 300
    Spring.NET学习笔记17——事务传播行为(基础篇) Level 200
    Spring.NET学习笔记13——AOP的概念(基础篇) Level 200
    Spring.NET学习笔记16——事务管理(应用篇) Level 200
  • 原文地址:https://www.cnblogs.com/janmson/p/1441660.html
Copyright © 2011-2022 走看看