2016-03-02 34 views
-2

在執行我收到錯誤即groovy.lang.MissingPropertyException腳本:沒有這樣的屬性:客戶ID類Groovy腳本錯誤沒有這樣的屬性:客戶ID爲

腳本

import org.w3c.dom.Node 
import org.w3c.dom.NodeList 
NodeList nodes = employeeServiceResponse.getFirstChild().getChildNodes() 
String firstName = null 
String lastName = null 
for (int i = 0 i < nodes.getLength() i++) { 
    Node node = nodes.item(i) 
    if ("firstName".equals(node.getLocalName())) 
    firstName = node.getFirstChild().getNodeValue() 
    else if ("lastName".equals(node.getLocalName())) 
    lastName = node.getFirstChild().getNodeValue() 
} 
if (firstName != null && lastName != null){ 
    println 'Found employee: ' + firstName + ' ' + lastName 
    discountPercent = 10 
    return true 
} else { 
    println 'Employee not found: ' + customerId 
    discountPercent = 0 
    return false 
} 

我新的常規腳本可以請任何人幫助我。腳本解析數據。

+0

你可以舉一些例子的XML?你是如何創建'employeeServiceResponse'? –

+0

customerId

回答

2

你寫(最後一行):

println 'Employee not found: ' + customerId 

customerId未在此腳本中定義。當你正在尋找你的腳本中的任何員工,你應該只寫:

println 'Employee not found' 
+0

K,感謝您的建議。 –

+0

但我沒有得到答覆。 –

+0

XML 客戶ID

相關問題