例如,在表单上有两个字段new_paymenttypeid和new_revenueid (它们是它们的id/字段名),我为它们创建一个委托,因为每次它们更改时,我都希望它们一起添加并存储在一个局部变量中。
Total = Attribute["new_paymenttypeid"].getValue() + Attribute["new_revenueid"].getValue()
Xrm.Page.getAttribute("new_paymenttypeid").addOnChange(PaymentTypeDependency);
Xrm.Page.getAttribute("new_revenueid").addOnChange(RevenueTypeDependency);我从下面的方法中读取了TotalRevenue的值,使用FetchXml,在父案例下可能有很多包含TotalRevenue的记录。我正在尝试做一个RertriveAllREcords从FetchXml下面。然后将SUM(TotalRevenue)从SUM(new_paymenttypeid + new_revenueid)中减去,并将其存储在另一种形式的字段中。该进程将以javascript的形式运行,如在change/on save/on load上运行。但这不起作用。我们正在使用Dynamic365Version8.2。由于这个原因,我被困在了CalculateSurplusdeficit方法中。我打算使用XMLHttpRequest API。如果您可以通过向我展示如何使用下面的查询(fetchXml)检索多条记录并创建处理程序来指导我,那么当我向这些文本框中输入数据时,它们就会被触发,以便它们可以在框中添加数字。在保存时,从Totapplicationtotalrevenue总收入中减去添加的数字,并在该实体表单上设置一个具有此值的字段。
function CalculateSurplusDeficit()
{
var caseId = Xrm.Page.data.entity.getId(); // case guid
//var grantYearLookup = Xrm.Page.getAttribute("new_grantyear").getValue();
//Retrieve Account Names whose Account Name Starts with word "M" using WEB API
//Step-1 : create fetch xml in adv find and replace all double quotes with single quote inside properties to shape it as a string
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> " +
"<entity name='new_applicationrevenue'> " +
" <attribute name='new_applicationtotalrevenue' /> " +
" <attribute name='new_grantyear' /> " +
" <order attribute='title' descending='false' /> " +
" <filter type='and'> " +
" <condition attribute='new_parentcase' operator='eq' uitype='incident' value='{'" + caseId + "}' /> " +
" </filter> " +
" </entity> " +
"</fetch> " ;
//Step-2 : encode URI : var encodedFetchXML = encodeURI(fetchxml)
var encodedFetchXML = encodeURI(fetchXml);
var data = {
"EntityId": caseId
};
//Step-3 : create a query path with query and odata partial uurl : var query = "/api/data/v8.0/accounts?fetchXml="+encodedFetchXML ;
var query = "/api/data/v8.2/Revenue?fetchXml=" + encodedFetchXML;
//Step-4 : create complete path : var path = Xrm.Page.context.getClientUrl() + query ;
var finalpathwithquery = Xrm.Page.context.getClientUrl() + query;
//Step-5 : create a XmlHttpRequest to retrieve data
var data = null;
var isAsync = false;
var req = new XMLHttpRequest();
req.open("POST",finalpathwithquery);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
data = result;
}
else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
//Step-6 show return result values
var acclist = null;
for(var i=0;i< data.value.length;i++){
Totapplicationtotalrevenue= Totapplicationtotalrevenue + data.value[i].new_applicationtotalrevenue;
}
}发布于 2021-01-19 21:30:33
下面的几处修改应该能使它发挥作用。
new_applicationrevenuesvar query = "/api/data/v8.2/new_applicationrevenues?fetchXml=" + encodedFetchXML;
GET而不是POST。调用可以是异步的,所以我将其保留为true。req.open("GET",finalpathwithquery,true);
如果(this.status === 200) { var结果= JSON.parse(this.response);data = result;for(var i=0;i< data.value.length;i++){ Totapplicationtotalrevenue= Totapplication之和收入+ data.valuei.new_applicationtotalrevenue;}
https://stackoverflow.com/questions/65789591
复制相似问题