crm中的子网格数据检索

Subgrid data retrival in crm

我有一个名为竞争对手的子网格动态 365 crm,我必须从该子网格获取数据并将其打印到警报中。我在网上搜索过,但是当我使用时从那里得到的每个解决方案都将错误作为已弃用的方法抛出。如何使用 JavaScript 在 dynamics 365 应用程序中获取子网格数据。谁能为此提供示例代码。 提前致谢

下面是我在我的一个实例中尝试过的代码。考虑到您想要对商机实体发出警报并且也需要加载表单。

使用调试器,您将获得数据。

function onLoad(executionContext){
debugger;
   var formContext = executionContext.getFormContext();   
var formType= formContext.ui.getFormType();
if(formType && formType!==1 && formContext.data.entity.getId()){
    retreiveOppCompRecords(formContext.data.entity.getId().replace(/[{}]/g, "")).then(
            function success(result) {              
             if(result.entities.length > 0){
                 for(i=0;i<result.entities.length;i++){

                 }               
             }               

            },
            function (error) {
                var alertStrings = {
                    confirmButtonLabel: "OK",
                    text: 'Failed at Function: enableDisableExpiryDate with error: ' + error.message
                };
                var alertOptions = {
                    height: 250,
                    width: 450
                };
                Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
            }
        );
}
}


function retreiveOppCompRecords(recordId){
    var fetchxml = ['<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">',
  '<entity name="opportunity" >',
    '<attribute name="name" />',
    '<filter type="and" >',
      '<condition attribute="opportunityid" operator="eq" value="' + recordId + '" />',
    '</filter>',
    '<link-entity name="opportunitycompetitors" from="opportunityid" to="opportunityid" alias="OppCompetitor" intersect="true" >',
      '<link-entity name="competitor" from="competitorid" to="competitorid" link-type="inner" alias="Competitor" >',
        '<attribute name="websiteurl" alias="CompetitorWebsite" />',
        '<attribute name="name" alias="CompetitoName" />',
      '</link-entity>',
    '</link-entity>',
  '</entity>',
'</fetch>'].join("");

    fetchxml = "?fetchXml=" + encodeURIComponent(fetchxml); 
    return Xrm.WebApi.retrieveMultipleRecords("opportunity", fetchxml);
}

正如 AnkUser 所躲避的那样,您需要从您的子网格中检索相关记录,并根据需要为您需要的列添加 <attribute name=''> 标签。

请记住,子网格只是数据视图,通常与给定记录相关联。

您具体要从子网格中检索什么?

我已经找到了答案 - 我已经通过 JavaScript 向子网格添加了一个 onload 事件,并使用 Xrm.Page.getControl(“entityname”).getGrid().

检索了数据