<?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>Refresh Variables are pass by reference?</title><link>https://community.appian.com/discussions/f/general/17489/refresh-variables-are-pass-by-reference</link><description>Okay so we came across a scenario that caused a bit of an argument: 
 
 Obviously this is a terrible idea in practice, however if we can put this aside the real concern is that when you do this changing the value of varB the change somehow back propagates</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Refresh Variables are pass by reference?</title><link>https://community.appian.com/thread/68934?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 14:06:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:edd15c57-1eef-4901-ae85-fb61e8d57828</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;That&amp;#39;s how it seems - or at least, it notices some difference between the object created directly from another object, versus by an expression (local!varA+2).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Refresh Variables are pass by reference?</title><link>https://community.appian.com/thread/68932?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 14:05:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f929f16c-b74b-4934-bc0e-5d4ca5168985</guid><dc:creator>jonathanb0001</dc:creator><description>&lt;p&gt;Seems like a deep/ shallow copy issue maybe?&lt;/p&gt;
&lt;p&gt;Appian Java code reads the first scenario as varA=varB and creates a shallow copy, and it reads the second as varA = varB+2 and creates a new object?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Refresh Variables are pass by reference?</title><link>https://community.appian.com/thread/68931?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 13:58:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1c93ff21-edd8-4f11-a3f8-3041af2d78b9</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Interestingly, with just a small change to the definition of local!varB, the form starts behaving how I would expect (i.e. refusing to saveInto directly into varB).&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;a!localVariables(
  local!varA: a!refreshVariable(
    value: rand()*100,
  ),
  local!varB: a!refreshVariable(
    value: local!varA + 2,
    refreshAlways: true
  ),
  a!sectionLayout(
    contents: {
      a!integerField(
        label: &amp;quot;Changes in this should change Var B&amp;quot;,
        value: local!varA,
        saveInto: local!varA
      ),
      a!integerField(
        label: &amp;quot;What happens here&amp;quot;,
        value: local!varB,
        saveInto: local!varB
      )
    }
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Refresh Variables are pass by reference?</title><link>https://community.appian.com/thread/68930?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 13:55:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8b133836-7a1e-4a03-9ae6-e9969e12c648</guid><dc:creator>jonathanb0001</dc:creator><description>&lt;p&gt;Yeah I was expecting the same error you see when you save into a time refresh var.&lt;/p&gt;
&lt;p&gt;Fun fact if var A is time refreshing you do get the error when saving into var b.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Refresh Variables are pass by reference?</title><link>https://community.appian.com/thread/68929?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 13:53:15 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e6cae507-3896-40c7-bb2c-d929d2a88ac7</guid><dc:creator>Carlos Santander</dc:creator><description>&lt;p&gt;The inline documentation for a!refreshVariable states:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em class="EmphasisText---richtext_emphasis"&gt;refreshAlways&lt;/em&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;Boolean&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;When true, the value of this local variable will be refreshed after each user interaction and each interval refresh. &lt;strong&gt;Because the variable is continually refreshed, you cannot update its value by saving into it.&lt;/strong&gt; Default: false.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Clearly the bolded text is not being enforced, but I&amp;#39;m guessing that&amp;#39;s what&amp;#39;s driving some of this behavior (i.e.,&amp;nbsp;you&amp;#39;re not supposed to be doing this to begin with, so unexpected behavior may occur.)&lt;/p&gt;
&lt;p&gt;Notice that varA doesn&amp;#39;t need to be a refresh variable itself. You can remove your refresh variable definition in lines 2-4 (still keeping varA there) and you&amp;#39;ll see the same behavior. Moreover, you can move varA to a load() outside of a!localVariables and you&amp;#39;ll still get the same behavior.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>