<?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 Re: VariableInstanceEntity saves value twice for new variables in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/variableinstanceentity-saves-value-twice-for-new-variables/m-p/112221#M78925</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Nice stuff you're doing, I must say &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://connect.hyland.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Indeed, the "setValue" is called twice. When you look at the VariableInstanceEntity, the setValue is called from create() and setValue() itself. Since the variables are designed to be stored in a ValueFields object which is only written once to the DB (at the end of the transaction) it's not really an issue. I get the point of this being a "redundant" call, but not sure this is something we will change because of the reasoning before.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you get the setValue-call, the command-context should be available in case there is an execution active (when the variable is set from within the execution, e.g.. javaDelegate or listener). I think that when using the runtime-service for setting variables, the execution-context will be absent. I'm afraid the VariableType approach is a bit isolated from the rest of the engine and it will be hard to get hold of the details you need in an easy way.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another suggestion I want to bring forward for this kind of requirement is overriding (perhaps subclassing/wrapping existing manager) the DBSqlSession. This is done by defining your own factory for it (forum contains some info on this, quite sure). This allows you override the insert(entity). Here you can first delegate to the activiti SQLSession and then, in case of a HistoricVariableUpdate, log whatever you want from here. The advantage is that the entity contains exeuction-id wheres the type doesn't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;On top of that, the insert is only called once, whereas the setValue() was called twice. IMHO, this fixes both of your problems.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Jul 2012 07:29:17 GMT</pubDate>
    <dc:creator>frederikherema1</dc:creator>
    <dc:date>2012-07-05T07:29:17Z</dc:date>
    <item>
      <title>VariableInstanceEntity saves value twice for new variables</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/variableinstanceentity-saves-value-twice-for-new-variables/m-p/112220#M78924</link>
      <description>Hi all,I'm trying to implement a custom VariableType (based on MongoDB) and noticed that VariableType.setValue() will be called twice when the affected variable did not yet exist in the current scope. The first call creates the new VariableInstanceEntity via VariableScopeImpl.createVariableLocal() a</description>
      <pubDate>Thu, 05 Jul 2012 07:04:30 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/variableinstanceentity-saves-value-twice-for-new-variables/m-p/112220#M78924</guid>
      <dc:creator>naag</dc:creator>
      <dc:date>2012-07-05T07:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: VariableInstanceEntity saves value twice for new variables</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/variableinstanceentity-saves-value-twice-for-new-variables/m-p/112221#M78925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Nice stuff you're doing, I must say &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://connect.hyland.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Indeed, the "setValue" is called twice. When you look at the VariableInstanceEntity, the setValue is called from create() and setValue() itself. Since the variables are designed to be stored in a ValueFields object which is only written once to the DB (at the end of the transaction) it's not really an issue. I get the point of this being a "redundant" call, but not sure this is something we will change because of the reasoning before.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you get the setValue-call, the command-context should be available in case there is an execution active (when the variable is set from within the execution, e.g.. javaDelegate or listener). I think that when using the runtime-service for setting variables, the execution-context will be absent. I'm afraid the VariableType approach is a bit isolated from the rest of the engine and it will be hard to get hold of the details you need in an easy way.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another suggestion I want to bring forward for this kind of requirement is overriding (perhaps subclassing/wrapping existing manager) the DBSqlSession. This is done by defining your own factory for it (forum contains some info on this, quite sure). This allows you override the insert(entity). Here you can first delegate to the activiti SQLSession and then, in case of a HistoricVariableUpdate, log whatever you want from here. The advantage is that the entity contains exeuction-id wheres the type doesn't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;On top of that, the insert is only called once, whereas the setValue() was called twice. IMHO, this fixes both of your problems.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2012 07:29:17 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/variableinstanceentity-saves-value-twice-for-new-variables/m-p/112221#M78925</guid>
      <dc:creator>frederikherema1</dc:creator>
      <dc:date>2012-07-05T07:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: VariableInstanceEntity saves value twice for new variables</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/variableinstanceentity-saves-value-twice-for-new-variables/m-p/112222#M78926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Activiti is a great software, so it inspires us to do nice things with it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually I like the VariableType idea. I use the fields TEXT_ and TEXT2_ to store information about the MongoDB document instance so it can be retrieved again later, so far so good. I thought it to be quite flexible.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regarding the context, I complete a task via BusinessProcess.completeTask() and this fetches the current task from the associationManager. So in a certain sense, an execution is active, but I guess not in the sense of the core-engine since CDI is just an extension. So now I will first try to acquire the BusinessProcess instance from the BeanManager and see where that takes me (not nice, but alright). Then later I will surely investigate your suggestion about extending DbSqlSession. I guess this is the better approach anyway &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks so much for your quick feedback, it's really helpful to get the right directions!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Peter&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2012 07:54:19 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/variableinstanceentity-saves-value-twice-for-new-variables/m-p/112222#M78926</guid>
      <dc:creator>naag</dc:creator>
      <dc:date>2012-07-05T07:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: VariableInstanceEntity saves value twice for new variables</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/variableinstanceentity-saves-value-twice-for-new-variables/m-p/112223#M78927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good luck with your quest &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://connect.hyland.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2012 09:14:58 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/variableinstanceentity-saves-value-twice-for-new-variables/m-p/112223#M78927</guid>
      <dc:creator>frederikherema1</dc:creator>
      <dc:date>2012-07-05T09:14:58Z</dc:date>
    </item>
  </channel>
</rss>

