我最近将 Outlook 客户端的 CRM 2011 添加到新机器上,我有一个在支付实体 formLoad 上运行的脚本,该脚本在考虑所有支付分配并从 TotalAmount 中扣除后计算剩余的金额。
但是,当我通过 Outlook 访问数据时,脚本似乎没有在 formLoad 上触发。如果我通过 Web 门户访问相同的数据,那么脚本会毫无问题地触发 - 这让我认为有一个设置您需要启用以允许自定义 javascript 在 Outlook for the CRM 中运行的位置?
我的 paymentLoad() 脚本如下:
function PaymentOnLoad() {
setTimeout(attachEventToGrid, 2500);
if (crmForm.ObjectId != null) {
var PaymentAmount = Xrm.Page.getAttribute("new_accountpaymentamount").getValue();
var OSAmount = CalcOutstandingPaymentAmount(crmForm.ObjectId);
Xrm.Page.getAttribute("new_remainingamount").setValue(parseFloat(eval(rounddec(OSAmount))));
if ((PaymentAmount != null) && (OSAmount - PaymentAmount != 0)) {
Xrm.Page.ui.controls.get("new_paymentamount").setDisabled(true);
}
}
}
function rounddec(value) {
return Math.round(value * 100) / 100;
}
function attachEventToGrid() {
// Attach a refresh event to the PaymentAllocations grid
var targetgrid = document.getElementById("PaymentAllocations");
if (targetgrid) {
if (targetgrid.control.add_onRefresh != undefined) {
targetgrid.control.add_onRefresh(ReLoad);
}
else {
targetgrid.attachEvent("onrefresh", ReLoad);
}
}
else {
setTimeout(attachEventToGrid, 2500);
}
}
function PaymentAllocationOnLoad() {
OnPaymentTypeSelection();
if (Xrm.Page.getAttribute("new_payment").getValue()[0] != null) {
var OSPaymentAmount = CalcOutstandingPaymentAmount(Xrm.Page.getAttribute("new_payment").getValue()[0].id);
Xrm.Page.getAttribute("new_paymentremainingamount").setValue(parseFloat(eval(OSPaymentAmount)));
if (Xrm.Page.getAttribute("new_invoice").getValue() != null) {
var OSInvoiceAmount = CalcOutstandingInvoiceAmount(Xrm.Page.getAttribute("new_invoice").getValue()[0].id);
Xrm.Page.getAttribute("new_invoiceremainingamount").setValue(parseFloat(eval(OSInvoiceAmount)));
Xrm.Page.ui.controls.get("new_paymentamount").setDisabled(true);
}
}
}
function CalcOutstandingPaymentAmount(paymentid) {
_oService = new FetchUtil(_sOrgName, _sServerUrl);
var sFetchPayment = "<fetch mapping='logical'>" +
"<entity name='new_payment'>" +
"<attribute name='new_paymentamount' />" +
"<attribute name='new_accountpaymentamount' />" +
"<filter type='and'>" +
"<condition attribute = 'new_paymentid' operator='eq' value='" + paymentid + "'/>" +
"</filter>" +
"</entity>" +
"</fetch>";
var fetchResultPayment = _oService.Fetch(sFetchPayment, null);
var sFetch = "<fetch mapping='logical'>" +
"<entity name='new_paymentinvoiceallocation'>" +
"<attribute name='new_allocatedamount' />" +
"<filter type='and'>" +
"<condition attribute = 'new_payment' operator='eq' value='" + paymentid + "'/>" +
"</filter>" +
"</entity>" +
"</fetch>";
var fetchApplication = _oService.Fetch(sFetch, null);
var TotalAmount = 0;
if (fetchResultPayment != null) {
TotalAmount = fetchResultPayment.results[0].attributes.new_accountpaymentamount.value;
}
if ((fetchResultPayment != null) && (fetchApplication != null)) {
for (var i = 0;
i < fetchApplication.results.length;
i++) {
TotalAmount -= fetchApplication.results[i].attributes.new_allocatedamount.value;
}
}
return TotalAmount;
}
任何建议,将不胜感激。