javascript - crm中的子网格数据检索
问题描述
我有一个名为竞争对手的子网格动态 365 crm 我必须从该子网格获取数据并将其打印到警报中。我在网上搜索过,但是当我使用时从那里得到的每个解决方案都将错误作为不推荐使用的方法。如何使用 JavaScript 在动态 365 应用程序中获取子网格数据。任何人都可以为此提供示例代码。提前致谢
解决方案
下面是我在我的一个实例中尝试过的代码。考虑到您希望对 Opportunity 实体发出警报,并且还需要加载表单。
使用调试器,您将获得数据。
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);
}
推荐阅读
- powerbi - PowerBI:计算表包含一个值而不是另一个值
- nginx - 如何使用 Nginx 提供 Redis 密钥?
- android - Flutter 使用 android 库的视图
- linux - Powershell Core 7.1.3 与 Bash/ZSH 相同的命令不同的输出。.. 为什么?
- python - .xslx 文件不会使用 openpyxl 返回单元格值
- spring - 无法获得令牌有效性
- r - 一张图中的多个箱线图
- javascript - 如何在自动格式化后阻止 VS Code 省略括号?
- ruby - 如何执行已发布的 Ruby Gem CLI 应用程序
- netsuite - 使用导入/上传删除记录