Finding a workbook that changes name daily

Hi,
How can I find a file or workbook (through “launch application”) that change name daily (its filename is ending with today’s date): This is the name ICAGR.UPDR.CSV.D181023.T021003 today. Tomorrow it will be ICAGR.UPDR.CSV.D181024.T021003.

Is it then also possible to change window (I guess so, since part of title is enough)?

Hi @peter.lundin

You can do it if you put the current date in a variable and then use the variable name in the Launch Application action

  1. Assign current date to a Date variable

  1. Convert Date to a String with the format you need

  1. Use the String variable’s name as part of the filepath. For example, C:\ICAGR.UPDR.CSV.D${today}.T021003.xlsx

Yes, to switch to the correct window, you can use the part of the filename that is stable

1 Like

Great, that worked well.

1 Like

And if I want to change to today -1 day?

@peter.lundin try using this custom action to get yesterday’s date

Sorry, I don’t get it? How do I use the script in the actions flow?

You need to calculate the yesterday’s date using custom script and then reformat it to a string

Execution fails on script

Could you share the screenshot of the custom script and the whole error text?

Error executing CustomScriptAction
  com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=CustomScriptAction.ftl,id=1,name=Optional[CustomScriptAction],parent=-1,nextSibling=2,arguments=ActionArguments[delay=[0],xsi:type=[recorder:CustomScriptAction, recorder:CustomScriptAction],name=[Yesterday],pollingInterval=[300],active=[true],actionDetails=[(Yesterday)],script=[@CustomScriptAction(
output = 'yesterday'
)

def customeScript() {
RDateTime.now().minus(java.time.Duration.ofDays(1))],awaitTimeout=[5000]]]
      at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:54)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
      at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:64)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:152)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: com.google.common.util.concurrent.UncheckedExecutionException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script2.groovy: 14: expecting '}', found '' @ line 14, column 1.
1 error

      at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2199)
      at com.google.common.cache.LocalCache.get(LocalCache.java:3932)
      at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936)
      at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806)
      at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4812)
      at com.workfusion.studio.rpa.recorder.playback.shell.compiler.EnabledGroovyScriptCache.compile(EnabledGroovyScriptCache.java:30)
      at com.workfusion.studio.rpa.recorder.playback.shell.GroovyShellWrapper.executeScript(GroovyShellWrapper.java:44)
      at com.workfusion.studio.rpa.recorder.playback.player.PlaybackContext.executeScript(PlaybackContext.java:65)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.executeBehavior(TemplateAction.java:33)
      at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:46)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
      at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:64)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:152)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script2.groovy: 14: expecting '}', found '' @ line 14, column 1.
1 error

      at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
      at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
      at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
      at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
      at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:144)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:110)
      at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234)
      at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:168)
      at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:943)
      at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
      at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
      at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
      at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:736)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:727)
      at com.workfusion.studio.rpa.recorder.playback.shell.compiler.GroovyShellCompiler.compile(GroovyShellCompiler.java:37)
      at com.workfusion.studio.rpa.recorder.playback.shell.compiler.EnabledGroovyScriptCache$1.load(EnabledGroovyScriptCache.java:22)
      at com.workfusion.studio.rpa.recorder.playback.shell.compiler.EnabledGroovyScriptCache$1.load(EnabledGroovyScriptCache.java:18)
      at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3522)
      at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2315)
      at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2278)
      at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2193)
      at com.google.common.cache.LocalCache.get(LocalCache.java:3932)
      at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936)
      at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806)
      at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4812)
      at com.workfusion.studio.rpa.recorder.playback.shell.compiler.EnabledGroovyScriptCache.compile(EnabledGroovyScriptCache.java:30)
      at com.workfusion.studio.rpa.recorder.playback.shell.GroovyShellWrapper.executeScript(GroovyShellWrapper.java:44)
      at com.workfusion.studio.rpa.recorder.playback.player.PlaybackContext.executeScript(PlaybackContext.java:65)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.executeBehavior(TemplateAction.java:33)
      at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:46)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
      at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
      at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:64)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:152)
      at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
      at java.lang.Thread.run(Thread.java:745)

You need a closing “}” at the end of the script:

@CustomScriptAction(
output = 'yesterday'
)

def customeScript() {
RDateTime.now().minus(java.time.Duration.ofDays(1))
}

Ah, sorry, missed that. The script seems to work now. However, something still doesn’t work. I am trying to find this excelfile, but I can’t: “C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE” -officeexcel" “C:\RPA\Projekt\Masterdata kontosaldon\ICAGR.UPDR.CSV.D${yesterday}.T021003.xls”

So I am doing something wrong in the actions flow I guess:

@peter.lundin can you share the details of the Launch application action?

If you want to open a particular file in it, you should insert the .exe file of the application and the file to open via a space, like: C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE C:\RPA\Projekt\Masterdata kontosaldon\ICAGR.UPDR.CSV.D${yesterday}.T021003.xls

Yes I have done that. No problem opening another file, where the name is constant, but this file, which is always having last swedish bankday in the name, doesn’t open. It keeps opening “Book1” instead.

The text in executable file is this: “C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE” -officeexcel" “C:\RPA\Projekt\Masterdata kontosaldon\ICAGR.UPDR.CSV.D${yesterday}.T021003.xls”

@peter.lundin is ${yesterday} a DateTime type of variable?

Yes it is.

image

This must be reason.
You need to use the String variable in the name - ${yesterday_string}

yes,you’re right. Thanks.

While we’re at it, do you know if it would be possible to , instead of “yesterday”, always choose a bank-day (so, no Saturdays or Sundays, but no bank holidays either - different in different countries of course - so probably with the help of a national calendar)