2 Replies Latest reply on May 20, 2008 10:29 AM by (JohnSpicer)

    When building a map in a loop, the first time through the map key is wrong

      Hi,

      I'm seeing some weird behaviour with the map data type. I'm trying to
      convert a list of attachments to a map of attachments. I have a map with
      subtype Document. I'm using a loop to iterate over the list and add
      the attachments to the map. My problem is that the first time through
      the loop, the map key is always being set the the value of the variable
      used in the route condition (i.e. if I start the loop at 1, the map key
      is set to an int value of 1, if I start the loop at 2, the map key is
      set to 2). The second time through the loop, the proper key is being
      used (which is a string value) and causes a java.lang.NumberFormatException.

      If I add a value to the map before entering the loop, everything works ok.

      Before entering the loop I have a variable mapping of:
      /process_data/@count = count(/process_data/attList)
      /process_data/@idx = 0

      I have a conditional route of:
      /process_data/@idx < /process_data/@count

      And inside the loop, I have variable mappings:
      /process_data/@idx = /process_data/@idx + 1
      /process_data/@attName = getDocAttribute(/process_data/attList[number(/process_data/@idx)],"name")
      /process_data/attMap[@id=/process_data/@attName] = /process_data/attList[number(/process_data/@idx)]

      The first iteration always results in a map key equal to the value of the idx variable.

      Not sure if I'm doing something wrong, or there's a bug.

      Thanks.