<?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>Fetch unique 3 character code</title><link>https://community.appian.com/discussions/f/rules/38233/fetch-unique-3-character-code</link><description>How to create list of unique 3 character alphabet code. If i pass &amp;quot;AAA&amp;quot; and 2, it should return &amp;quot;AAB&amp;quot;, &amp;quot;AAC&amp;quot;. 2 unique codes after &amp;quot;AAA&amp;quot;</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143991?ContentTypeID=1</link><pubDate>Wed, 01 Jan 2025 10:59:37 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:91da4a81-ec57-4ba3-b161-cbc3821d2ef1</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;You need a recursive expression. I created the helper function&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1735729038048v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!newQuotient: floor(ri!quotient / 26),
  local!newRemainders: append(
    ri!remainders,
    mod(ri!quotient, 26)
  ),
  if(
    local!newQuotient &amp;gt; 0,
    rule!SSH_DecTo26Helper(
      quotient: local!newQuotient,
      remainders: local!newRemainders
    ),
    local!newRemainders
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And call it like this&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;index(
  char(enumerate(26) + 65),
  rule!SSH_DecTo26Helper(
    quotient: ri!value,
    remainders: {}
  ) + 1
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Line 2 represents the characters A..Z. The &amp;quot;+1&amp;quot; shifts the numbers from 0..25 to 1..26. ri!value is an integer. In your case this would be the integer primary key generated in the database.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143984?ContentTypeID=1</link><pubDate>Tue, 31 Dec 2024 22:48:28 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2f41d431-4d07-4212-910d-a3f9256b930f</guid><dc:creator>shivas3219</dc:creator><description>&lt;p&gt;ri!input is 3 char code e.g &amp;quot;WXY&amp;quot; and&amp;nbsp;ri!iterationCount is number of codes i need. i have given input as&amp;nbsp;&amp;quot;WXY&amp;quot; but it generated wrong codes&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143983?ContentTypeID=1</link><pubDate>Tue, 31 Dec 2024 22:45:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a961f8ab-ce5b-4887-88aa-eafd06208778</guid><dc:creator>shivas3219</dc:creator><description>&lt;p&gt;&lt;a href="/members/stefanhelzle0001"&gt;Stefan Helzle&lt;/a&gt;&amp;nbsp; I have below code but its not working in every case&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!splitByArray: char(code(ri!input)),
  local!convertedToBase26: tointeger(rule!SS_getIdByAlphabet(local!splitByArray[1])) * power(26, 2) + 
  tointeger(rule!SS_getIdByAlphabet(local!splitByArray[2])) * power(26, 1) + 
  tointeger(rule!SS_getIdByAlphabet(local!splitByArray[3])) * power(26, 0),
  local!listOfGettableNumbers: tointeger(local!convertedToBase26) + enumerate(ri!iterationCount) + 1,
  local!setOfCodes: a!forEach(
    items: tointeger(local!listOfGettableNumbers),
    expression: a!localVariables(
      local!thirdCharacter: rule!SS_getAlphabetById(tointeger(mod(fv!item, 26))),
      local!secondCharacter: rule!SS_getAlphabetById(
        tointeger(mod(rounddown(fv!item / 26, 0), 26))
      ),
      local!divisionResult: rounddown(rounddown(fv!item / 26, 0) / 26, 0),
      local!firstCharacter: rule!SS_getAlphabetById(
        rounddown(mod(local!divisionResult, 26), 0)
      ),
      concat(
        local!firstCharacter,
        local!secondCharacter,
        local!thirdCharacter
      )
    )
  ),
  local!setOfCodes
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143982?ContentTypeID=1</link><pubDate>Tue, 31 Dec 2024 20:51:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:bff88eca-5432-4808-ace5-76808ed0d9f1</guid><dc:creator>shivas3219</dc:creator><description>&lt;p&gt;&lt;a href="/members/stefanhelzle0001"&gt;Stefan Helzle&lt;/a&gt;&amp;nbsp;Thank you very much. I will try this method.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143974?ContentTypeID=1</link><pubDate>Tue, 31 Dec 2024 10:16:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6fde8c63-af2c-41ec-9c46-fea2faf77545</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Did you consider to let the database create the integer primary key, and then derive your alphabet code from this? Then you are sure to never have any duplicates. This needs a transformation from the decimal numeric system into a system based on the number 26. You can then store this code in a separate field.&lt;/p&gt;
&lt;p&gt;I general I doubt that this is a good design decision, but that&amp;#39;s up to you to decide.&lt;/p&gt;
&lt;p&gt;For the implementation, you might want to use the reduce() function. Check my blog post for how to implement such algorithms in Appian:&amp;nbsp;&lt;a href="https://appian.rocks/2022/08/29/complex-algorithms-in-appian/"&gt;appian.rocks/.../&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I asked GPT for how to do that:&lt;/p&gt;
&lt;p&gt;To transform a number from the decimal system (base 10) into a numeric system using the letters A-Z (which can be interpreted as a base-26 system), you can follow these steps:&lt;/p&gt;
&lt;p&gt;1. **Understand the Mapping**: In this system, you can map the numbers as follows:&lt;br /&gt; - 1 = A&lt;br /&gt; - 2 = B&lt;br /&gt; - 3 = C&lt;br /&gt; - ...&lt;br /&gt; - 26 = Z&lt;br /&gt; - 27 = AA&lt;br /&gt; - 28 = AB&lt;br /&gt; - and so on.&lt;/p&gt;
&lt;p&gt;2. **Conversion Process**:&lt;br /&gt; - Subtract 1 from the decimal number to adjust for zero-based indexing.&lt;br /&gt; - Divide the number by 26.&lt;br /&gt; - The remainder will give you the letter (0 corresponds to A, 1 to B, ..., 25 to Z).&lt;br /&gt; - Continue dividing the quotient by 26 until it reaches 0.&lt;br /&gt; - Collect the letters in reverse order.&lt;/p&gt;
&lt;p&gt;### Example:&lt;br /&gt;Let&amp;#39;s convert the decimal number 28 to this system.&lt;/p&gt;
&lt;p&gt;1. **Initial Number**: 28&lt;br /&gt;2. **Subtract 1**: 28 - 1 = 27&lt;br /&gt;3. **Divide by 26**: &lt;br /&gt; - 27 &amp;divide; 26 = 1 (Quotient)&lt;br /&gt; - Remainder = 27 % 26 = 1 (which corresponds to A)&lt;br /&gt;4. **Next Step**: &lt;br /&gt; - Now take the quotient (1).&lt;br /&gt; - 1 - 1 = 0 (stop here since the quotient is now 0).&lt;br /&gt; - 0 &amp;divide; 26 = 0 (Quotient)&lt;br /&gt; - Remainder = 0 % 26 = 0 (which corresponds to A)&lt;br /&gt;5. **Collect Letters**: The letters collected are A (from the last step) and A (from the first step), so we read them in reverse order: AA.&lt;/p&gt;
&lt;p&gt;Thus, the decimal number 28 is represented as &amp;quot;AB&amp;quot; in this system.&lt;/p&gt;
&lt;p&gt;### Another Example:&lt;br /&gt;Convert 703 to this system.&lt;/p&gt;
&lt;p&gt;1. **Initial Number**: 703&lt;br /&gt;2. **Subtract 1**: 703 - 1 = 702&lt;br /&gt;3. **Divide by 26**:&lt;br /&gt; - 702 &amp;divide; 26 = 27 (Quotient)&lt;br /&gt; - Remainder = 702 % 26 = 0 (which corresponds to A)&lt;br /&gt;4. **Next Step**:&lt;br /&gt; - 27 - 1 = 26&lt;br /&gt; - 26 &amp;divide; 26 = 1 (Quotient)&lt;br /&gt; - Remainder = 26 % 26 = 0 (which corresponds to A)&lt;br /&gt;5. **Next Step**:&lt;br /&gt; - 1 - 1 = 0 (stop here).&lt;br /&gt; - 0 &amp;divide; 26 = 0 (Quotient)&lt;br /&gt; - Remainder = 0 % 26 = 0 (which corresponds to A)&lt;br /&gt;6. **Collect Letters**: The letters collected are A (from the last step), A (from the second step), and A (from the first step), so we read them in reverse order: AAA.&lt;/p&gt;
&lt;p&gt;Thus, the decimal number 703 is represented as &amp;quot;AAA&amp;quot; in this system.&lt;/p&gt;
&lt;p&gt;Feel free to provide a specific decimal number if you want me to convert it for you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143973?ContentTypeID=1</link><pubDate>Tue, 31 Dec 2024 09:08:26 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1da3eabc-de20-4434-87ec-f5e9d642c328</guid><dc:creator>shivas3219</dc:creator><description>&lt;p&gt;&amp;nbsp;&lt;a href="/members/stefanhelzle0001"&gt;Stefan Helzle&lt;/a&gt;&amp;nbsp; could you please suggest how to get number of unique codes I need, using above design gives me values till AAZ, but I need further codes for my requirement&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143970?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 20:19:51 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:22261c50-3ce2-41dd-9cc3-aefca33df3aa</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Well ... then, good luck with this design.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143969?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 19:44:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:eae5c754-1277-4aec-9e55-18282d20356a</guid><dc:creator>shivas3219</dc:creator><description>&lt;p&gt;There will be only user who would be updating it for now. I agree that it may create some&amp;nbsp;conflicting values with multiple users. This code is being used in mapping to other tables.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143968?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 19:21:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a44d5620-4bab-40fc-991f-191e473ba30f</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Sorry, but this will generate conflicting values as soon as multiple users create rows. There is a good reason for why we use the database to create these values.&lt;/p&gt;
&lt;p&gt;For what purpose do you need these values? And why not just use the numeric primary key values from the database?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143967?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 19:05:37 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:43fb6ce3-12ad-46e6-9921-690357da7a26</guid><dc:creator>shivas3219</dc:creator><description>&lt;p&gt;&lt;a href="/members/stefanhelzle0001"&gt;Stefan Helzle&lt;/a&gt;&amp;nbsp;This is not a primary key but unique code to identify the record and some other stuff.&amp;nbsp; I would have created a dictionary of unique 3 char code&amp;nbsp;but it may degrade performance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143966?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 18:51:51 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8ff59305-9fab-4ce4-a545-d1bfab2cd77d</guid><dc:creator>venkatrea696188</dc:creator><description>[quote userid="252725" url="~/discussions/f/rules/38233/fetch-unique-3-character-code/143964"]it saves in database with generated unique code in a column[/quote]
&lt;p&gt;In this case we can suggest multiple approaches. The approach you mentioned , I don&amp;#39;t suggest it for various reasons&amp;nbsp; .&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;One would be incremental number (simple approach).&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Generating UUID&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Or appending timestamp to a Application prefix or something like that(It&amp;#39;s going to be unique every time) , the list goes on&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143965?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 18:49:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9f29e7f6-6260-4c8b-994d-f66882b159bf</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Are you sure this&amp;nbsp;is a good way to solve the problem of primary key values?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143964?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 18:30:38 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5b7e2dd0-6cc6-430c-8212-bb67c2f9ccbb</guid><dc:creator>shivas3219</dc:creator><description>&lt;p&gt;When i add new records to the editable grid, it saves in database with generated unique code in a column. If i create 3 new rows, it needs 3 new codes to be generated to assign it to each row. There may situations where end user can delete already added row and at that time we need to recreate codes and assign to each row accordingly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143963?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 18:25:47 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e20620e6-fc83-4c6b-8b82-ebf710952cb2</guid><dc:creator>venkatrea696188</dc:creator><description>&lt;p&gt;Yup it&amp;#39;s gonna give you that .I just pasted sample code how it needs be done&amp;nbsp;&lt;/p&gt;
[quote userid="21957" url="~/discussions/f/rules/38233/fetch-unique-3-character-code/143960"]Very curious as to why you would need to do this[/quote]
&lt;p&gt;Same here ,Can I know why you need this in the first place . We can suggest alternatives&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143961?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 17:32:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1e747316-7db2-43ce-8258-dc9dd746c109</guid><dc:creator>shivas3219</dc:creator><description>&lt;p&gt;Thanks all for the response. &amp;nbsp;If i pass &amp;quot;AAZ&amp;quot; and 2. its returning &amp;quot;&lt;span class="CollapsibleOutputNode---print_value"&gt;AA[&amp;quot; and &amp;quot;AA\&amp;quot; where it should be &amp;quot;ABA&amp;quot; and &amp;quot;ABB&amp;quot;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143960?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 14:59:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3a964a5f-5f8a-4032-8158-532fd6bc9917</guid><dc:creator>Mathieu Drouin</dc:creator><description>&lt;p&gt;Random != Unique.&lt;/p&gt;
&lt;p&gt;Very curious as to why you would need to do this but here is some code to generate a string variable length with random characters. Not unique though. You should look into UUIDs if you want to achieve this.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!character: &amp;quot;A&amp;quot;,
  local!numberOfCharactersToAppend: 2,
  local!allCharacters: &amp;quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&amp;quot;,
  local!charactersToAppend: a!forEach(
    items: enumerate(local!numberOfCharactersToAppend),
    expression: a!localVariables(
      local!randomIndex: rounddown((rand() * 26 + 1), 0),
      mid(
        local!allCharacters,
        local!randomIndex,
        1
      )
    )
  ),
  concat(
    local!character,
    joinarray(local!charactersToAppend, &amp;quot;&amp;quot;)
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fetch unique 3 character code</title><link>https://community.appian.com/thread/143955?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2024 11:52:48 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:514e19ca-3ee3-4e44-b63a-bae038d1f7f0</guid><dc:creator>venkatrea696188</dc:creator><description>&lt;p&gt;Couple of questions , where you intended to use this and the limit of iteration count ?? This you can write using &lt;strong&gt;Code and char function&amp;nbsp;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Pasting a Sample code for your reference , You need to change the code if the iteration count is more than 25&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!inputcodes: if(
    a!isNullOrEmpty(ri!input),
    null,
    code(ri!input)
  ),
  local!iterate: a!forEach(
    items: enumerate(ri!iterationCount+1),
    expression: a!localVariables(
      local!index:fv!item,
    concat(
      char(local!inputcodes[1]),
      char(local!inputcodes[2]),
      char(local!inputcodes[3] + local!index)
    ))
  ),
  local!iterate
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>