2016-03-02 65 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

相关问题