【问题标题】:Using Groovy to capture the last day of the previous month使用 Groovy 捕获上个月的最后一天
【发布时间】:2021-02-25 16:11:56
【问题描述】:

我在 Boomi 中使用 Groovy(1.5) 来捕捉上个月的最后一天,并且我一直在混合我通过 Google 找到的一些东西:

import java.util.Properties;
import java.io.InputStream;

for( int i = 0; i < dataContext.getDataCount(); i++ ) {
    InputStream is = dataContext.getStream(i);
    Properties props = dataContext.getProperties(i);

    dataContext.storeStream(is, props);
}

var dt = new Date(); 
dt.setDate(1);  
dt.setHours(-1); 

props.setProperty("document.dynamic.userdefined.StartDate",dt);

但我遇到了以下错误:

No signature of method: com.sun.script.groovy.GroovyScriptEngine.var() is applicable for argument types: (java.util.Date) values: {Thu Feb 25 16:09:33 UTC 2021} (in groovy script);
 Caused by: No signature of method: com.sun.script.groovy.GroovyScriptEngine.var() is applicable for argument types: (java.util.Date) values: {Thu Feb 25 16:09:33 UTC 2021}

【问题讨论】:

  • 属性是字符串,所以你需要在使用setProperty()之前转换成一个。
  • 仅供参考,如果您错过导入,这不是您会得到的错误。那将是 ClassNotFoundException (或相关的)。当您获得“无方法签名”时,这意味着没有方法可以接受您发送它的类型的参数。在这种情况下,java.util.Date 的类型。
  • 类似String newdt = dt.format("yyyy-MM-dd'T'HH:mm:ss.SSSZZ"); 然后传入 newdt 而不是 dt。

标签: groovy boomi


【解决方案1】:

var 是 JavaScript 保留关键字。解决此错误的两种方法:

  1. 使用 JavaScript 作为语言:

  2. 将var 替换为def:

    def dt = new Date();
    dt.setDate(1);
    dt.setHours(-1);
    

【讨论】:

    猜你喜欢
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多