<?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 Is there a way to access both before- and after- document metadata during a documentModified handler? in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313486#M487</link>
    <description>&lt;P&gt;I have a multivalue metadata element on my custom document type. I would like to run code when this information changes, but I need to know which items were added or removed from the list of elements in order to run this code.&lt;/P&gt;
&lt;P&gt;Simplified examples:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Document contains ['item1'] - user adds 'item2' to this list and clicks Save.  My handler runs and sees that the value has changed from ['item1'] to ['item1', 'item2'] for this element. It performs work for the new 'item2'.&lt;/LI&gt;
&lt;LI&gt;Document contains ['item1', 'item2'] - user removes 'item1' from this list and clicks Save. My handler runs and sees that the value has changed from ['item1', 'item2'] to ['item2']. It performs work for the old 'item1'.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;There must be several ways to implement this, but it is a simple enough concept that I think there must be a "best" way in the general case. Could someone give a general outline or a pointer to existing code/documentation that handles metadata changes on documentModified?&lt;/P&gt;</description>
    <pubDate>Wed, 20 Nov 2013 23:00:53 GMT</pubDate>
    <dc:creator>Steven_Huwig1</dc:creator>
    <dc:date>2013-11-20T23:00:53Z</dc:date>
    <item>
      <title>Is there a way to access both before- and after- document metadata during a documentModified handler?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313486#M487</link>
      <description>&lt;P&gt;I have a multivalue metadata element on my custom document type. I would like to run code when this information changes, but I need to know which items were added or removed from the list of elements in order to run this code.&lt;/P&gt;
&lt;P&gt;Simplified examples:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Document contains ['item1'] - user adds 'item2' to this list and clicks Save.  My handler runs and sees that the value has changed from ['item1'] to ['item1', 'item2'] for this element. It performs work for the new 'item2'.&lt;/LI&gt;
&lt;LI&gt;Document contains ['item1', 'item2'] - user removes 'item1' from this list and clicks Save. My handler runs and sees that the value has changed from ['item1', 'item2'] to ['item2']. It performs work for the old 'item1'.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;There must be several ways to implement this, but it is a simple enough concept that I think there must be a "best" way in the general case. Could someone give a general outline or a pointer to existing code/documentation that handles metadata changes on documentModified?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2013 23:00:53 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313486#M487</guid>
      <dc:creator>Steven_Huwig1</dc:creator>
      <dc:date>2013-11-20T23:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to access both before- and after- document metadata during a documentModified handler?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313487#M488</link>
      <description>&lt;P&gt;You can have access to the origninal document model (the one containing old values, not the one being modified) with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@{Document.getRef().reference()}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Nov 2013 15:33:10 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313487#M488</guid>
      <dc:creator>jmdavid_8121</dc:creator>
      <dc:date>2013-11-21T15:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to access both before- and after- document metadata during a documentModified handler?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313488#M489</link>
      <description>&lt;P&gt;Thanks. I am doing this from inside Java code, however. I'm not sure what the equivalent of the above is, but &lt;CODE&gt;input.getCoreSession().getDocument(input.getRef())&lt;/CODE&gt; seems to get the same metadata as is on &lt;CODE&gt;input&lt;/CODE&gt; during documentModified.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2013 23:06:30 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313488#M489</guid>
      <dc:creator>Steven_Huwig1</dc:creator>
      <dc:date>2013-11-21T23:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to access both before- and after- document metadata during a documentModified handler?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313489#M490</link>
      <description>&lt;P&gt;The answer to this question is to hook into the "before document modification" and retrieve the document from the repository.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;public String run(DocumentModel input) throws ClientException {
    DocumentModel oldDocument = session.getDocument(input.getRef());
    // ...
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the above method, "input" contains the new values and "oldDocument" contains the old values.&lt;/P&gt;
&lt;P&gt;My original question assumed "documentModified" was the correct event, but it was not.&lt;/P&gt;
&lt;P&gt;edit: see &lt;A href="https://answers.nuxeo.com/questions/7394/is-there-a-way-to-access-both-before-and-after-document-metadata-during-a-documentmodified-handler/8822"&gt;the better answer&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2014 16:35:34 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313489#M490</guid>
      <dc:creator>Steven_Huwig1</dc:creator>
      <dc:date>2014-05-01T16:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to access both before- and after- document metadata during a documentModified handler?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313490#M491</link>
      <description>&lt;P&gt;The better answer is to use the previous document that's already provided to you in the event context for a &lt;CODE&gt;beforeDocumentModification&lt;/CODE&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;DocumentModel oldDocument = (DocumentModel) context.getProperty(CoreEventConstants.PREVIOUS_DOCUMENT_MODEL);
if (oldDocument != null) {
    // beforeDocumentModification
    title = oldDocument.getTitle();
    // ...
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 May 2014 14:45:07 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313490#M491</guid>
      <dc:creator>Florent_Guillau</dc:creator>
      <dc:date>2014-05-02T14:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to access both before- and after- document metadata during a documentModified handler?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313491#M492</link>
      <description>&lt;P&gt;Thank you! I knew there must have been a better way; I just had no idea how to find it.&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2014 15:23:09 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/is-there-a-way-to-access-both-before-and-after-document-metadata/m-p/313491#M492</guid>
      <dc:creator>Steven_Huwig1</dc:creator>
      <dc:date>2014-05-02T15:23:09Z</dc:date>
    </item>
  </channel>
</rss>

