【问题标题】:Global function works in preview but fails when code is run全局函数在预览中有效,但在运行代码时失败
【发布时间】:2019-04-15 01:13:34
【问题描述】:

我有一个名为“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>

DataWeave 代码:

//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)

任何帮助表示赞赏

【问题讨论】:

    标签: anypoint-studio dataweave cloudhub mulesoft


    【解决方案1】:

    这是全局函数中的 cmets 的问题。所以删除或修改该行:

     <!-- 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>
    

    或者将你的 cmets 修改为 //

    <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>
    

    【讨论】:

    • 非常感谢
    猜你喜欢
    • 2015-05-19
    • 2021-03-12
    • 2019-12-20
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    • 2019-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多