Monday, June 4, 2018

WFA advanced incremental naming

In a previous post, I already explained how incremental naming works.  (http://www.wfaguy.com/2016/12/incremental-naming.html#more)

However, sometimes you need something a bit more advanced.
For example you need this incremental functionality

- myvol50xx
- myvol51yy
- myvol52zz
Using the classic incremental naming functionality, this no longer works as we have a changing suffix.

In this case you need to follow these steps :
  1. create a custom filter with regex (e.g. WHERE name REGEXP '${regex}'
    Search for the last item by using this regex '^myvol[0-9]{2}.*$
    => Hint : use skip this step if not found !
  2. Then use the _found property like this :
    (volume_last._found)?Integer.parseInt(getRegexMatch(volume_last.name,"^(myvol)([0-9]{2})(.*)$",2))+1:1

    This seems complex, but isn't.
    • If last volume found
      • Strip number from last volume
        • regex = ^myvol([0-9]{2})(.*)$
          This regex will parse your name and create 4 matches (using the brackets)
          Match 0 = the full string
          Match 1 = the string "myvol"
          Match 2 = the number
          Match 3 = the suffix
          In our case, we grab match 2 (the number)
      • And increase by 1
    • If not found
      • Return 1
  3. Finally use the number to reassemble the new name
    'myvol' + padNumber(NEW_NUMBER,2) + 'mysuffix'
The function "getRegexMatch", you can find on my github (https://www.github.com/wfaguy

Along this function you can find interesting others.  I recently added a few new ones like :
  • trimEnd
  • getRegexMatch
  • getLastNumber
  • getLastNumberWithSuffix

No comments :

Post a Comment