<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Arcade question in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1172224#M411</link>
    <description>&lt;P&gt;Hello Everyone, I have a Arcade question. I am trying to set up a calculation rule that populate a value in a &lt;STRONG&gt;text type&lt;/STRONG&gt; field based on a previous value.&lt;/P&gt;&lt;P&gt;For example, an original value is '1234567' and what I want to do is replace this value with the original value plus 1, i.e. '1234568'.&lt;/P&gt;&lt;P&gt;I tried a code below in the expression builder of the calculation rule but it does not work - a value returns but it is not the correct value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;'attributes': {
    'A_Id': Text(Number(feature.A_Id) + 1,'0000000')}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Any tips are much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 May 2022 22:15:56 GMT</pubDate>
    <dc:creator>Aнастасия88</dc:creator>
    <dc:date>2022-05-09T22:15:56Z</dc:date>
    <item>
      <title>Arcade question</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1172224#M411</link>
      <description>&lt;P&gt;Hello Everyone, I have a Arcade question. I am trying to set up a calculation rule that populate a value in a &lt;STRONG&gt;text type&lt;/STRONG&gt; field based on a previous value.&lt;/P&gt;&lt;P&gt;For example, an original value is '1234567' and what I want to do is replace this value with the original value plus 1, i.e. '1234568'.&lt;/P&gt;&lt;P&gt;I tried a code below in the expression builder of the calculation rule but it does not work - a value returns but it is not the correct value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;'attributes': {
    'A_Id': Text(Number(feature.A_Id) + 1,'0000000')}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Any tips are much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 22:15:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1172224#M411</guid>
      <dc:creator>Aнастасия88</dc:creator>
      <dc:date>2022-05-09T22:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade question</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1172283#M413</link>
      <description>&lt;P&gt;Hmmm, it seems to work:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1652160828315.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/40968iC017168CA6D6AB3C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1652160828315.png" alt="JohannesLindner_0-1652160828315.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you give an example of original values where it doesn't return the correct value?&lt;/P&gt;&lt;P&gt;Can you post the whole code, maybe your problem is in another part?&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 05:36:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1172283#M413</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-05-10T05:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade question</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1173070#M417</link>
      <description>&lt;P&gt;Thanks for your reply!&lt;/P&gt;&lt;P&gt;I just realised that there is a threshold in digit number to convert string to number. 16 digits works but if it is more than that, it does not work.&lt;/P&gt;&lt;P&gt;Now I am thinking of split the text, convert them to number to update the value, and then concatenate them back to text. But is there any other better way to achieve this?&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 22:17:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1173070#M417</guid>
      <dc:creator>Aнастасия88</dc:creator>
      <dc:date>2022-05-11T22:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade question</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1173205#M418</link>
      <description>&lt;P&gt;Ah, so you're dealing with numbers too big for Arcade.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;But is there any other better way to achieve this?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;If you have a constant part in your ID that doesn't change, you could remove that, convert the rest to number (hopefully smaller than 16 digits) and increase, then concatenate back.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If the whole ID is a number, then you probably will have to split it up. This isn't super easy, though, because you have to take care of a few things:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;if the last part is "9", you can't just change it to "10" and concatenate&lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;wrong: "1239" + 1&amp;nbsp; --&amp;gt;&amp;nbsp; "12310".&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;right: "1239" + 1&amp;nbsp; --&amp;gt;&amp;nbsp; "1240"&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;if a part starts with "0", you will have to add that back in&lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;wrong: "00123" + 1&amp;nbsp; &amp;nbsp;--&amp;gt;&amp;nbsp; "124"&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;right: "00123" + 1&amp;nbsp; --&amp;gt;&amp;nbsp; "00124"&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I came up with this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function increase (txt) {
    // split text into parts
    // part_length has to be smaller than 16
    var txt_length = Count(txt)
    var part_length = 15
    var parts = []
    for(var i = 0; i &amp;lt; txt_length; i += part_length) {
        Push(parts, Mid(txt, i, part_length))
    }
    for(var i = Count(parts) - 1; i &amp;gt;= 0; i -= 1) {
        // add 1 to the last element
        var old_part = parts[i]
        var new_part = Text(Number(old_part) + 1)
        parts[i] = new_part
        if(Count(new_part) &amp;lt; Count(old_part)) {
            // New_part is shorter (eg "000" -&amp;gt; "1")
            // add padding and break the loop
            var diff = Count(old_part) - Count(new_part)
            for(var j = 0; j &amp;lt; diff; j += 1) {
                parts[i] = "0" + parts[i]
            }
            break
        }
        if(Count(new_part) == Count(old_part) || i == 0) {
            // the part's length did not change or this is the first element
            // we're done, break the loop
            break
        }
        if(Count(new_part) &amp;gt; Count(old_part)) {
            // New_part is longer (eg "999" -&amp;gt; "1000")
            // remove the first digit and continue the loop
            parts[i] = Mid(new_part, 1, part_length)
            continue
        }
    }
    return Concatenate(parts)
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is pretty long, maybe it can be done in a simpler way...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function test(txt) {
    Console(txt +"\n" + increase(txt) + "\n")
}

test("00000")
test("98")
test("99")
test("1234567890123456789012345678901234567890")  // 40 digits!
test("9999999999999999999999999999999999999999")
test("10000000000000000000000000000000000000000")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;00000
00001

98
99

99
100

1234567890123456789012345678901234567890
1234567890123456789012345678901234567891

9999999999999999999999999999999999999999
10000000000000000000000000000000000000000

10000000000000000000000000000000000000000
10000000000000000000000000000000000000001&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 09:07:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1173205#M418</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-05-12T09:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade question</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1173572#M420</link>
      <description>&lt;P&gt;Thanks Johannes for your advice!&lt;/P&gt;&lt;P&gt;As you said, I would need to figure out the nature of the text value to make decision which way to go. Hopefully, there is a constant part of less than 16 digits. Also thanks a lot for giving the example of a code - this would help me a lot!&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 23:58:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-question/m-p/1173572#M420</guid>
      <dc:creator>Aнастасия88</dc:creator>
      <dc:date>2022-05-12T23:58:08Z</dc:date>
    </item>
  </channel>
</rss>

