<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to Auto Increment Alpha Characters in an expression rule to create sequential ID&amp;#39;s</title><link>https://community.appian.com/discussions/f/rules/10347/how-to-auto-increment-alpha-characters-in-an-expression-rule-to-create-sequential-id-s</link><description>Hello, 
 I&amp;#39;m looking for a way to automatically increment a set of 4 alpha characters given a rule input of an existing set of 4 characters. 
 
 For example if the rule is passed AAAA it returns AAAB, if the rule is passed AABA it returns AABB, if the</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to Auto Increment Alpha Characters in an expression rule to create sequential ID's</title><link>https://community.appian.com/thread/45712?ContentTypeID=1</link><pubDate>Thu, 25 May 2017 06:46:43 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6adbb253-f9f4-4128-bc64-304d20296520</guid><dc:creator>harshav</dc:creator><description>Thanks for all the answers. They work great.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to Auto Increment Alpha Characters in an expression rule to create sequential ID's</title><link>https://community.appian.com/thread/45688?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 19:18:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c3a98e46-137b-4d81-94e8-7907b6d4f4fc</guid><dc:creator>jasonf</dc:creator><description>&lt;p&gt;Thanks to immense help from Jackie, here&amp;#39;s the set of rules that seem to work for this as best as I&amp;#39;ve tested so far. (In case anyone else ever needs it)&lt;/p&gt;
&lt;p&gt;ri!allowedLetters is a passed in constant with a text array of letters allowed to be used for incrementation&lt;br /&gt;ri!inputString is the original alpha string passed in&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;load(
  
  local!newString: null,
  
  local!arrayWithString:
    rule!GBL_incrementAlphaString(
      allowedLetters: ri!allowedLetters,
      inputString: ri!inputString,
      newString: local!newString
    ),
    
  local!updatedString:
    index(
      local!arrayWithString,
      count(local!arrayWithString), null
    ),
    
  local!updatedString
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GBL_incrementAlphaString&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
  reduce(
    rule!GBL_alphaStringIncrementer(
      newString:_,
      position:_,
      allowedLetters: ri!allowedLetters,
      inputString: ri!inputString
    ),
    {},
    reverse(enumerate(len(ri!inputString))+1)
  )
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a class="gwt-Anchor" rel="tooltip"&gt;GBL_alphaStringIncrementer&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;with(
  local!letter: index(ri!inputString, ri!position, null),
  local!index: wherecontains(local!letter, ri!allowedLetters),
  local!nextLetter: 
    if(
      or(
        rule!APN_isBlank(ri!inputString),
        local!index = count(ri!allowedLetters)
      ),
      index(ri!allowedLetters, 1, null),
      index(ri!allowedLetters, local!index+1, null)
    ),

  local!indexLowerLetter: 
    index(ri!allowedLetters,
      wherecontains(index(ri!newString, ri!position+1, null), ri!allowedLetters),
      null 
    ),
    
  local!lastPositionChangedFromZ: 
    toboolean(index(ri!newString, count(ri!newString)-1, null)),
  {
    local!index = count(ri!allowedLetters),
    
    if(
      ri!position = len(ri!inputString),
    
      replace(ri!inputString, ri!position, 1, local!nextLetter),
      
      
      if(
        local!lastPositionChangedFromZ,
        replace(index(ri!newString, count(ri!newString), null), ri!position, 1, local!nextLetter),
        ri!newString
      )
    )
  }
)

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to Auto Increment Alpha Characters in an expression rule to create sequential ID's</title><link>https://community.appian.com/thread/45642?ContentTypeID=1</link><pubDate>Tue, 23 May 2017 19:04:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:15a80de4-3c2a-4ff5-9e1c-ef9790cceee6</guid><dc:creator>Jackie Jubien</dc:creator><description>&lt;p&gt;This allows you to make this an extremely dynamic rule - by using reduce()&lt;/p&gt;
&lt;p&gt;load(&lt;br /&gt; reduce(&lt;br /&gt; rule!jcj_testingAlphaIncrementer(&lt;br /&gt; &lt;br /&gt; newId:_,&lt;br /&gt; position:_,&lt;br /&gt; allowedLetters: ri!allowedLetters,&lt;br /&gt; lastIdAlpha:ri!lastIdAlpha&lt;br /&gt; ),&lt;br /&gt; {},&lt;br /&gt; reverse(enumerate(len(ri!lastIdAlpha))+1)&lt;br /&gt; )&lt;br /&gt;)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;with(&lt;br /&gt; local!letter: index(ri!lastIdAlpha, ri!position, null),&lt;br /&gt; local!index: wherecontains(local!letter, ri!allowedLetters),&lt;br /&gt; local!nextLetter: &lt;br /&gt; if(&lt;br /&gt; or(&lt;br /&gt; rule!APN_isBlank(ri!lastIdAlpha),&lt;br /&gt; local!index = count(ri!allowedLetters)&lt;br /&gt; ),&lt;br /&gt; index(ri!allowedLetters, 1, null),&lt;br /&gt; index(ri!allowedLetters, local!index+1, null)&lt;br /&gt; ),&lt;br /&gt; local!indexLowerLetter: &lt;br /&gt; index(ri!allowedLetters,&lt;br /&gt; wherecontains(index(ri!newId, ri!position+1, null), ri!allowedLetters),&lt;br /&gt; null &lt;br /&gt; ),&lt;br /&gt; &lt;br /&gt; if(ri!position = count(ri!allowedLetters),&lt;br /&gt; &lt;br /&gt; replace(ri!lastIdAlpha, ri!position, 1, local!nextLetter),&lt;br /&gt; &lt;br /&gt; if(&lt;br /&gt; local!indexLowerLetter = &amp;quot;A&amp;quot;,&lt;br /&gt; replace(ri!newId, ri!position, 1, local!nextLetter),&lt;br /&gt; ri!newId&lt;br /&gt; )&lt;br /&gt; )&lt;br /&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to Auto Increment Alpha Characters in an expression rule to create sequential ID's</title><link>https://community.appian.com/thread/45634?ContentTypeID=1</link><pubDate>Tue, 23 May 2017 17:20:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c51c0525-6c62-4e41-8ba3-4d9465095d9e</guid><dc:creator>jasonf</dc:creator><description>Thank you I will play with this. I intend to have a rule input for how many characters are being passed in, and whether or not bytes can be added once all Z&amp;amp;#x27;s are reached or not and if so how many etc.  Thanks for the response.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to Auto Increment Alpha Characters in an expression rule to create sequential ID's</title><link>https://community.appian.com/thread/45633?ContentTypeID=1</link><pubDate>Tue, 23 May 2017 16:57:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:60f7fa1c-ca6a-4ab6-b5c2-e6db36a0c386</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I&amp;#39;m sure this can be done more gracefully if you utilize looping, but the following expression works as far as I can tell (though you&amp;#39;d want to add failsafes for the case where fewer than 4 characters get passed in):&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;with(
  
  local!codes: code(ri!input),
  local!A: 65,
  local!Z: 90,
  
  local!4thChar: if(local!codes[4] = local!Z, local!A, local!codes[4]+1),
  local!4thCharCarry: if(local!codes[4] = local!Z, 1, 0),
  
  local!3rdChar: if(local!codes[3]+local!4thCharCarry &amp;gt; local!Z, local!A, local!codes[3]+local!4thCharCarry),
  local!3rdCharCarry: if(local!codes[3]+local!4thCharCarry &amp;gt; local!Z, 1, 0),
  
  local!2ndChar: if(local!codes[2]+local!3rdCharCarry &amp;gt; local!Z, local!A, local!codes[2]+local!3rdCharCarry),
  local!2ndCharCarry: if(local!codes[2]+local!3rdCharCarry &amp;gt; local!Z, 1, 0),
  
  local!1stChar: if(local!codes[1]+local!2ndCharCarry &amp;gt; local!Z, local!A, local!codes[1]+local!2ndCharCarry),
  
  concat(char({ local!1stChar, local!2ndChar, local!3rdChar, local!4thChar }))
  
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>