<?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 best to add/remove selections</title><link>https://community.appian.com/discussions/f/data/38957/how-best-to-add-remove-selections</link><description>I have an interface where a user is able to click on several choices in a checkbox. Each selection is stored as a separate row in a data table that is linked to their user data. Adding new choices is easy as you just write a new row for that box. Removing</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How best to add/remove selections</title><link>https://community.appian.com/thread/147362?ContentTypeID=1</link><pubDate>Fri, 18 Apr 2025 20:11:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:38e5d306-2bff-4033-a84e-04f54093fffb</guid><dc:creator>Mathieu Drouin</dc:creator><description>&lt;p&gt;If you found my advice helpful, please consider marking the response as verified. Thanks! :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How best to add/remove selections</title><link>https://community.appian.com/thread/147361?ContentTypeID=1</link><pubDate>Fri, 18 Apr 2025 20:02:27 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:947c832b-a199-4a1f-a3f1-aa0871449f45</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;The &amp;quot;best practice&amp;quot; (IMHO) is to not remove but instead deactivate rows that a user un-selects in this manner (via an &amp;quot;active flag&amp;quot; row or a &amp;quot;removed flag&amp;quot; row, both the same thing except for being opposite in value).&amp;nbsp; The question then becomes, what happens if a user re-selects previously un-selected rows?&amp;nbsp; The code is a little trickier but it helps prevent DB rows from getting spammed if you implement a system that looks up any deactivated rows for the current user and marks them as re-activated if they&amp;#39;re re-selected (instead of selected for the first time).&amp;nbsp; IMHO it&amp;#39;s worth the time and hassle to implement.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How best to add/remove selections</title><link>https://community.appian.com/thread/147360?ContentTypeID=1</link><pubDate>Fri, 18 Apr 2025 20:01:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8364d88a-e778-432d-a165-d90ea92bfb10</guid><dc:creator>Marco Tacca</dc:creator><description>&lt;p&gt;gotcha, so I come up with separate lists of things to add and things to remove. Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How best to add/remove selections</title><link>https://community.appian.com/thread/147359?ContentTypeID=1</link><pubDate>Fri, 18 Apr 2025 19:49:48 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7ad6c8cb-af67-46cf-8a80-c4edecdb7c99</guid><dc:creator>Mathieu Drouin</dc:creator><description>&lt;p&gt;Here is an simple example using local variables:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!checkBoxesFromDB: {
    a!map(id: 1, value: &amp;quot;ITEM_1&amp;quot;),
    a!map(id: 2, value: &amp;quot;ITEM_2&amp;quot;)
  },
  local!checkBoxValue: local!checkBoxesFromDB.value,
  local!checkBoxesToAdd,
  local!checkBoxesToRemove,
  {
    a!checkboxField(
      label: &amp;quot;Check box field&amp;quot;,
      choiceLabels: { &amp;quot;Item 1&amp;quot;, &amp;quot;Item 2&amp;quot;, &amp;quot;Item 3&amp;quot; },
      choiceValues: { &amp;quot;ITEM_1&amp;quot;, &amp;quot;ITEM_2&amp;quot;, &amp;quot;ITEM_3&amp;quot; },
      value: local!checkBoxValue,
      saveInto: {
        local!checkBoxValue,
        a!save(
          local!checkBoxesToAdd,
          a!forEach(
            items: local!checkBoxValue,
            expression: a!map(id: fv!index, value: fv!item)
          )
        ),
        a!save(
          local!checkBoxesToRemove,
          difference(
            cast(
              typeof({ a!map() }),
              local!checkBoxesFromDB
            ),
            cast(
              typeof({ a!map() }),
              local!checkBoxesToAdd
            )
          )
        )
      }
    )
  }
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>