我不太懂 JS,所以试图找出这个错误。任何帮助将不胜感激。
错误: 指定的参数超出了有效值的范围。参数名称:System.Object[] 类型的类没有名为 AL 的属性
这是我的代码:
var tempPolicyNum = "XXXXXXXX";
var record1 = ctx.Db.ExecuteSQL("Select pol.Premium as Premium,pol.PolicyNumber,pol.PolicyLines from Custom__IncentiveProgram CIP LEFT JOIN Members mem ON CIP.MemberID = mem.MemberID LEFT JOIN Policies pol ON mem.MemberID = pol.MemberID and pol.CustomCode13ID = CIP.FundYearID where pol.PolicyNumber="+ "'" + tempPolicyNum + "'")
var GL_NP = 0, AL_NP=0, PR_NP=0, WC_NP=0;
var premiumTotal = 0;
var tableArr = [];
if(record1.Length>0){
for(var i in record1){
var premiumValue = parseFloat(record1[i].Premium ? String(record1[i].Premium).replace(/[$,]/g, '') : '0');
premiumTotal += premiumValue;
if(record1[i].PolicyLines == "|8|"){
WC_NP=record1[i].Premium;
}
if(record1[i].PolicyLines == "|9|"){
GL_NP=record1[i].Premium;
}
if(record1[i].PolicyLines == "|1|"){
AL_NP=record1[i].Premium;
}
if(record1[i].PolicyLines.includes("|2|")){
PR_NP=record1[i].Premium;
}
}
}
tableArr.push({
GL: GL_NP,
AL: AL_NP,
PR: PR_NP,
WC: WC_NP,
Total: '$'+ (Math.round(premiumTotal).toLocaleString('en-US')).toString().split('.')[0]
});
return tableArr;
尽管错误是针对 C# 的,但它是由 JavaScript 代码返回的数据结构引起的。
JavaScript 返回
tableArr
,它是一个包含单个对象的数组。使用的 C# 代码可能需要一个具有 AL
等属性的对象,而不是数组。
尝试直接返回对象,而不是包装在数组中。
var tempPolicyNum = "XXXXXXXX";
var record1 = ctx.Db.ExecuteSQL("Select pol.Premium as Premium,pol.PolicyNumber,pol.PolicyLines from Custom__IncentiveProgram CIP LEFT JOIN Members mem ON CIP.MemberID = mem.MemberID LEFT JOIN Policies pol ON mem.MemberID = pol.MemberID and pol.CustomCode13ID = CIP.FundYearID where pol.PolicyNumber="+ "'" + tempPolicyNum + "'")
var GL_NP = 0, AL_NP=0, PR_NP=0, WC_NP=0;
var premiumTotal = 0;
if(record1.Length>0){
for(var i in record1){
var premiumValue = parseFloat(record1[i].Premium ? String(record1[i].Premium).replace(/[$,]/g, '') : '0');
premiumTotal += premiumValue;
if(record1[i].PolicyLines == "|8|"){
WC_NP=record1[i].Premium;
}
if(record1[i].PolicyLines == "|9|"){
GL_NP=record1[i].Premium;
}
if(record1[i].PolicyLines == "|1|"){
AL_NP=record1[i].Premium;
}
if(record1[i].PolicyLines.includes("|2|")){
PR_NP=record1[i].Premium;
}
}
}
var resultObj = {
GL: GL_NP,
AL: AL_NP,
PR: PR_NP,
WC: WC_NP,
Total: '$' + Math.round(premiumTotal).toLocaleString('en-US').split('.')[0]
};
return resultObj;