anypoint-studio - 全局函数在预览中有效,但在运行代码时失败
问题描述
我有一个名为“finalPrice”的全局函数,它在我的 configuration.xml 文件中定义。该函数接受一个值 - 对其进行处理 - 并返回最终值。我从 DataWeave 中引用该函数。当我单击“预览”时,我可以在预览窗口中看到正确的输出。但是,当我运行它时,我得到了错误:
消息:执行时出现异常:
没有名为“finalPrice”的变量。
我已经在本地机器和 CloudHub 上运行了代码,得到了相同的结果
XML 代码:
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
<!-- This function is called by the 'Validate and Transform' dataweave component in the 'main' flow-->
def finalPrice(incoming_value)
{
import java.lang.String;
import java.math.RoundingMode;
// Do Stuff
return strFinalNumber;
}
</global-functions>
</expression-language>
</configuration>
数据编织代码:
//Refer to "finalPrice" Global Function in the main.xml configuration file
DB_FINL_PRCE: "field_missing" when payload01.DB_FINL_PRCE == "" otherwise finalPrice(payload01.DB_FINL_PRCE)
任何帮助表示赞赏
解决方案
这是全局函数中的注释的问题。所以删除或修改该行:
<!-- This function is called by the 'Validate and Transform' dataweave component in the 'main' flow-->
并且只有:
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
def finalPrice(incoming_value)
{
import java.lang.String;
import java.math.RoundingMode;
// Do Stuff
return strFinalNumber;
}
</global-functions>
</expression-language>
</configuration>
或将您的评论修改为 //
<configuration doc:name="Configuration">
<expression-language autoResolveVariables="true">
<global-functions>
//This function is called by the 'Validate and Transform' dataweave component in the 'main' flow
def finalPrice(incoming_value)
{
// Do Stuff
return "somethingelse";
}
</global-functions>
</expression-language>
</configuration>
推荐阅读
- pandas - 调整和重新索引漂移时间索引数据帧
- node.js - NestJS 视图未添加到 Dist
- swift - 数组中的解析值未显示在表格视图中
- swift - 无法理解如何使用 url-scheme
- flutter - 如何在 Flutter 中更新内部小部件
- openapi - 如何从 OpenAPI 3.0 中的数组模式中引用另一个模式?
- apache-spark - 如何将结构数组转换为多列?
- solr - Apache Nutch REST API 从运行 Nutch 的服务器检索数据?
- android - 如何从nodemcu发送和接收数据?
- laravel - 新用户登录时的laravel中间件重定向