<?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>Problem with refreshing value of a variable</title><link>https://community.appian.com/discussions/f/data/19204/problem-with-refreshing-value-of-a-variable</link><description>Hi, 
 I got a form with an editable grid layout. on each row it can be added an amount. This is populated by a Rule input that contains : 
 
 FeuilleFrais -&amp;gt; CDT 
 FeuilleFrais.montantTotal -&amp;gt; total amount. 
 FeuilleFrais.listeFrais -&amp;gt; list of another</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Problem with refreshing value of a variable</title><link>https://community.appian.com/thread/75210?ContentTypeID=1</link><pubDate>Mon, 06 Jul 2020 13:09:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9c27da2a-1929-4eb4-b4cc-8ae27c461dd6</guid><dc:creator>alex.ladue</dc:creator><description>&lt;p&gt;No problem. Yes - creating a rule would be a good way to simplify the logic.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with refreshing value of a variable</title><link>https://community.appian.com/thread/75209?ContentTypeID=1</link><pubDate>Mon, 06 Jul 2020 12:59:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5bcee19a-a4e9-40fa-8818-e8833415e9df</guid><dc:creator>nicolasc0003</dc:creator><description>&lt;p&gt;Thanks for the explanation, now I do understand the logic behind the behavior I get.&lt;/p&gt;
&lt;p&gt;I guess that in order to avoid to duplicate the logic to multiple place I will have to create a rule&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with refreshing value of a variable</title><link>https://community.appian.com/thread/75208?ContentTypeID=1</link><pubDate>Mon, 06 Jul 2020 12:37:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8771be07-9012-4609-9362-1f10b94bbe57</guid><dc:creator>alex.ladue</dc:creator><description>&lt;p&gt;Hi Nicolas,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure I totally understand the set up of your expression, but I think I may know what is happening. Basically, variables refresh *after* all saves are completed - this is how SAIL works. So in your case, you would need to put the logic to update local!otal in our saveInto before you do&amp;nbsp;&lt;span&gt;a!save(ri!FeuilleFrais.montantTotal, local!total) since local!total will refresh after the save have been completed. I plan to add an example of this to the documentation shortly. Here is a preview of that:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;When a component&amp;#39;s value is updated and its saveInto parameter is evaluated, all saves inside of the saveInto parameter are evaluated before any local variables are refreshed. This means that saving into a local variable and attempting to use another local variable which depends on the first local variable&amp;#39;s value later in the saveInto will still use the original value of the second local variable.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s look at an example to which illustrates this behavior.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!number,
  local!greaterThanFive: tointeger(local!number) &amp;gt; 5,
  local!message,
  {
    a!integerField(
      label: &amp;quot;Enter number&amp;quot;,
      instructions: local!message,
      value: local!number,
      saveInto: {
        local!number,
        a!save(
          target: local!message,
          value: if(
            local!greaterThanFive,
            &amp;quot;This number is greater than five&amp;quot;,
            &amp;quot;This number is less than or equal to five&amp;quot;
          )
        )
      }
    )
  }
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In this example, I have 3 variables:&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!number&lt;/code&gt;,&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!greaterThanFive&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;, and&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!message&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class="highlighter-rouge"&gt;local!number&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is used to hold the value of the number entered in the integer field.&lt;/li&gt;
&lt;li&gt;&lt;code class="highlighter-rouge"&gt;local!greaterThanFive&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;checks if&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!number&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is greater than 5. This value will automatically refresh when its dependent,&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!number&lt;/code&gt;, is updated.&lt;/li&gt;
&lt;li&gt;&lt;code class="highlighter-rouge"&gt;local!message&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;will hold a message after entering a number.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Typing a number into the integer field will trigger the saveInto of the integer field to be evaluated. First, the value entered is saved into&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!number&lt;/code&gt;. Then, a message is saved into&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!message&lt;/code&gt;. In this&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;a!save()&lt;/code&gt;, the value is determined by an&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;if&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;statement which uses&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!greaterThanFive&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;to check if our value is greater than five and returns the corresponding message to be displayed in the instructions.&lt;/p&gt;
&lt;p&gt;However, if we test this out by typing in the number&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;7&lt;/code&gt;, we see that the message returned is&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;&amp;quot;This number is less than or equal to five&amp;quot;&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;instead of&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;&amp;quot;This number is greater than five&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The incorrect message is returned because&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!greaterThanFive&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;does not refresh until all of the saves have completed in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;saveInto&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;parameter of the integer field.&lt;/p&gt;
&lt;p&gt;The correct way to achieve the behavior we are looking for would be the following:&lt;/p&gt;
&lt;div class="language-sail highlighter-rouge"&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!number: 0,
  local!message,
  {
    a!integerField(
      label: &amp;quot;Enter number&amp;quot;,
      instructions: local!message,
      value: local!number,
      saveInto: {
        local!number,
        a!save(
          target: local!message,
          value: if(
            tointeger(local!number) &amp;gt; 5,
            &amp;quot;This number is greater than five&amp;quot;,
            &amp;quot;This number is less than or equal to five&amp;quot;
          )
        )
      }
    )
  }
)&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In this version, we remove&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;local!greaterThanFive&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and place the logic directly in our&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="highlighter-rouge"&gt;a!save&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function, which allows for that condition to correctly be evaluated during the save.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>