2016-11-11 26 views
0

我想插入下面​​的默認值,當我運行服務我得到這個下面的錯誤任何一個請告訴我如何解決。當我運行多執行語句服務時,我得到了錯誤「無法讀取屬性」參數「null」

腳本運行時錯誤( 「過程: 'CustomPersonalGS實踐' ProcessItem: '初始化' 類型: '項'」 -1:-1).TypeError:無法從空讀取屬性 「參數」

enter image description here

enter image description here

//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); 
 
\t addParam(tw.local.customerPD.customerPersonalDetailsList[i].customerId,"VARCHAR","IN"); 
 
\t addParam(tw.local.customerPD.customerPersonalDetailsList[i].custPersonalDetailsId,"VARCHAR","IN"); 
 
\t var yesNoFlag = "N"; 
 
\t if(tw.local.customerPD.customerPersonalDetailsList[i].isBPMEnabled){ 
 
\t \t yesNoFlag="Y"; 
 
\t \t addParam(yesNoFlag,"CHAR","IN"); 
 
\t } 
 
\t yesNoFlag = "N"; 
 
\t if(tw.local.customerPD.customerPersonalDetailsList[i].isCCPEnabled){ 
 
\t \t yesNoFlag="Y"; 
 
\t \t addParam(yesNoFlag,"CHAR","IN"); 
 
\t } 
 
\t yesNoFlag = "N"; 
 
\t if(tw.local.customerPD.customerPersonalDetailsList[i].isCCPMandatory){ 
 
\t \t yesNoFlag="Y"; 
 
\t \t addParam(yesNoFlag,"CHAR","IN"); 
 
\t } 
 
\t yesNoFlag = "N"; 
 
\t if(tw.local.customerPD.customerPersonalDetailsList[i].isLatestVersion){ 
 
\t \t yesNoFlag="Y"; 
 
\t \t addParam(yesNoFlag,"CHAR","IN"); 
 
\t } 
 
} \t

回答

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

0

這種比較永遠不能正常工作。 array[array.length]將永遠是null(第35行)。

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

此外,在下一行,如果你想用列表的最後一個元素的工作,你可能想使用類似array[array.length - 1]。就個人而言,我會使用一些臨時變量,用它做一些事情,並在末尾插入到列表中(類似於@Drux's answer)。

相關問題