如何将软编码元素传递到crm Web资源脚本

时间:2019-06-16 23:18:02

标签: dynamics-crm

我无法将元素名称传递到Dyanamics CRM Web资源Javacript中。

此代码有效:

function OnFormLoad()
    {
        var subGrid = window.parent.document.getElementById("Claims")
        // do work 
    }

此代码不:

function OnFormLoad(GridName)
    {
        var subGrid = window.parent.document.getElementById(GridName)
        // do work 
    }

如何传递要使用的元素的名称?

1 个答案:

答案 0 :(得分:2)

请避免在Dynamics中使用document.getElementById,因为它不受支持。

我相信您正在尝试获取GridContext并从该Grid获取数据。

对于“客户”实体的示例,我们将“联系人”作为网格,然后您希望从该网格获取数据。

我在客户实体(OnLoad)上复制了相同的内容,并尝试从Contacts Grid中获取数据。

添加OnLoad事件时,我已将网格名称作为参数传递如下。

enter image description here

我在下面的Account实体上添加了onLoad Js,并能够从网格中检索数据。

注意:我添加了超时,因为直接触发onload无法加载整个页面,因此网格名称不可用。

function onLoad(executionContext,gridName){

setTimeout(function(){ getGridDatat(executionContext,gridName); }, 3000);


}

function getGridDatat(executionContext,gridName){
    debugger
var formContext = executionContext.getFormContext();

    var gridContext = formContext.getControl("Contacts"); // get the grid context
    var myRows = gridContext.getGrid().getRows();
/*var myRow = myRows.get(arg);
var gridRowData = myRow.getData();*/
var firstRow =myRows.get(0).getData();
    var firstRowAllAttributes = firstrow.entity.attributes.getAll()

    var firstRowfirstAttributeValue = firstrow.entity.attributes.get(0).getValue()

}

如果要对更改formGird数据执行一些操作,那么还有另一种方法可以实现此目的。将网格设置为“可编辑”,然后可以如下所示查找该网格的事件并执行操作。

enter image description here