Groovy job shows uncomprehensible behaviour

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Groovy job shows uncomprehensible behaviour


      i´m not sure whether this is a Jedox/Palo or a Groovy problem. I have the following script that loops over a list of files in order to load each via a job.

      _ def state1=null;
      _ new File("c:\\import").eachFileMatch(~/.*.csv/) { file->
      ___ state1 = API.executeLoad("strLoadStage");
      ___ if (state1.isOK()){
      _____ state2 = API.executeLoad("strLoadCore");
      ___ } else {
      _____ boolean fileMoved = file.renameTo(new File(FailDir, file.getName()));
      ___ }
      _ }

      This works fine until a first error occurs and the "state" variable gets set to FALSE. Even though the next call of the load job is successful
      the "state" variable´s value somehow remains FALSE thus leading to the ELSE branch being executed,

      Does the "state" variable need to be reset or something?
    • Hi OMartin,

      just for my comprehension, I don't understand why you iterate on each file and don't set the name of the file in your file connection:

      strLoadStage is a Load, right ? if I understand well this uses a file extract so this file extract should be variable over your loop, right ?

      what if you reinitalize the state1 variable after your if ?

      Post hoc, non est propter hoc
    • Hi Laloune,

      I do set the file name. I just trimmed the original script in order to focus only on the relevant part.

      Yes, strLoadStage is a file extract/load, followed by a relational load if it was successful.

      I think re-initializing state1 is exactly what is needed here, because obviously it keeps it´s value for whatever reason, even if it has been used for a second invocation of the load.

      So, how can i re-initialize it? Unfortunately i´m neither a Groovy nor a java developer (obviuosly).
    • Hi OMartin,

      try the following:

      Source Code

      1. def state1=null;
      2. new File("c:\\import").eachFileMatch(~/.*.csv/) {
      3. file->
      4. state1 = API.executeLoad("strLoadStage");
      5. isStateOK=state1.isOK();
      6. LOG.Info(isStateOK);
      7. if (isStateOK)
      8. {
      9. state2 = API.executeLoad("strLoadCore");
      10. } else {
      11. boolean fileMoved = file.renameTo(new File(FailDir, file.getName()));
      12. }
      13. isStateOK=false;
      14. }
      Display All

      can you also provide your xml file so that we can look into it what's going on ?

      Post hoc, non est propter hoc
    • I just learned (from Jedox Support) that the returned state object won´t change anymore. It is actually meant to be evaluated once at the end of the containing procedure only, to show whether or not errors have occured.

      So i´ll have to use a work-around employing the getErrors() method of the state object, which should just increase with each error that occurs within the procedure..

      The post was edited 1 time, last by OMartin ().