0

我想在运行服务时插入以下默认值,但出现以下错误,请告诉我如何解决。

脚本中的运行时错误(“进程:'CustomPersonalGS Practice' ProcessItem:'Initialize'类型:'ITEM'”-1:-1)。TypeError:无法从 null 读取属性“参数”

在此处输入图像描述

在此处输入图像描述

//Initialise SQL Query List
tw.local.sqlQueries =  new tw.object.listOf.SQLStatement();
tw.local.sql = "";

tw.local.customerPD = new tw.object.customerPD1BO();
tw.local.customerPD.customerPersonalDetailsList = new tw.object.listOf.customerSpecificPersonalDetailsListBO();
var custPersonalDetails = new tw.object.customerSpecificPersonalDetailsListBO();
custPersonalDetails.customerId = "8467";
custPersonalDetails.custPersonalDetailsId = "8";
custPersonalDetails.isBPMEnabled = true;
custPersonalDetails.isCCPEnabled = true;
custPersonalDetails.isCCPMandatory = true;
custPersonalDetails.isLatestVersion = true
tw.local.customerPD.customerPersonalDetailsList.insertIntoList(tw.local.customerPD.customerPersonalDetailsList.listLength, custPersonalDetails);


tw.local.sql = "INSERT INTO CUSTOMPERSONALDETAILSQUESTION(CUSTOMERID,CUSTPERSONLADETAILSID,ISBPMENABLED,ISCCPENABLED,ISCCPMANDATORY,ISLATESTVERSION) VALUES (?,?,?,?,?,?) ";

function addSQLStatement() {
  tw.local.sqlQueries[tw.local.sqlQueries.listLength] = new tw.object.SQLStatement();
}

function addParam(value,type,mode) {
  log.info("VALUE :" + value);
  var newParam = new tw.object.SQLParameter();
  newParam.value = value;
  newParam.type = type;
  newParam.mode = mode;
     if( tw.local.sqlQueries == null){
         tw.local.sqlQueries = new tw.object.listOf.SQLStatement();
     }
    if( tw.local.sqlQueries[tw.local.sqlQueries.listLength] == null ){
         tw.local.sqlQueries.insertIntoList(tw.local.sqlQueries.listLength, new tw.object.SQLStatement());
    }
    if(tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters == null ){
        tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters = new tw.object.listOf.SQLParameter();
    }
  var paramsLength = tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters.listLength;
  tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters[paramsLength] = newParam;
}

for(var i=0;i<tw.local.customerPD.customerPersonalDetailsList.listLength;i++){
    addSQLStatement(tw.local.sql);
	addParam(tw.local.customerPD.customerPersonalDetailsList[i].customerId,"VARCHAR","IN");
	addParam(tw.local.customerPD.customerPersonalDetailsList[i].custPersonalDetailsId,"VARCHAR","IN");
	var yesNoFlag = "N";
	if(tw.local.customerPD.customerPersonalDetailsList[i].isBPMEnabled){
		yesNoFlag="Y"; 
		addParam(yesNoFlag,"CHAR","IN");
	}
	yesNoFlag = "N";
	if(tw.local.customerPD.customerPersonalDetailsList[i].isCCPEnabled){
		yesNoFlag="Y"; 
		addParam(yesNoFlag,"CHAR","IN");
	}
	yesNoFlag = "N";
	if(tw.local.customerPD.customerPersonalDetailsList[i].isCCPMandatory){
		yesNoFlag="Y"; 
		addParam(yesNoFlag,"CHAR","IN");
	}
	yesNoFlag = "N";
	if(tw.local.customerPD.customerPersonalDetailsList[i].isLatestVersion){
		yesNoFlag="Y"; 
		addParam(yesNoFlag,"CHAR","IN");
	}
}	

4

2 回答 2

0

这种比较永远不会正常工作。array[array.length]将永远是null(第 35 行)。

if (tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters == null ){

此外,在接下来的几行中,如果您想使用列表的最后一个元素,您可能需要使用类似array[array.length - 1]. 就个人而言,我会使用一些临时变量,用它做一些事情并将其插入到最后的列表中(类似于@Drux's answer)。

于 2016-11-27T06:13:22.470 回答
0

据我所知,您没有在 SQL 中初始化参数列表。那就是你打电话的第38行 -

  var paramsLength = tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters.listLength;

但是,当您在 tw.local.sqlQueries 中创建条目时,您没有初始化参数数组。我还会注意到您的 addSQLStatement() 函数忽略了 sql 输入(并且该值是硬编码的,因此您实际上不需要将其传递进去)。我认为如果您将 addSQLStatement 更改为 -

function addSQLStatement(query) {
  var targetQuery = new tw.object.SQLStatement();
  targetQuery.sql = query;
  tagetQuery.params = new tw.object.listOf.SQLParameter();
  tw.local.sqlQueries[tw.local.sqlQueries.listLength] = targetQuery;
}

那么您的代码将起作用。此外,您实际上可以从此函数返回 targetQuery,然后将其传递给“addParams”方法,从而无需查找数组中的最后一个。或者将其插入数组的开头,然后只更新第 0 项而不是最后一项。

-AP

于 2016-11-18T18:32:17.627 回答