- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
12m ago
If you want to move a custom app between instances, you publish it to the app repository. But that moves the app, not the records in it. What about transactional data: an incident, a case, or a record in your own custom table, with its work notes, attachments and field changes? Moving it is easier than you'd expect: two XML exports. There's one gotcha, though. If you skip the second export, the activity stream shows a history that never happened. In this article I use an incident to walk through the method and show how I proved each step on my PDIs.
The Problem:
You export the incident as XML and import it into the target. The work notes and attachments come across. But the field changes are missing, and the creation entry in the activity stream shows values the record never had
Short answer:
You need two exports, not one: the record XML and the record's sys_audit rows. Import sys_audit before anyone opens the record on the target. You don't need to export sys_history_set, because the platform builds it when the form is opened
The tables involved:
- sys_journal_field: work notes and comments. Comes with the record XML.
- sys_attachment and sys_attachment_doc: attachments and their file content. Come with the record XML.
- sys_audit: one row per field change. Does not come with the record XML.
- sys_history_set: the activity stream's saved history. Built from sys_audit when the form is opened.
Here's How I Proved It on My PDI
Step 1: Create a test incident on the source.
On my source PDI, I created INC0010033 and gave it some history: an attachment, two work notes, one comment, a state change (New to In Progress), an urgency change and an impact change (3 - Low to 2 - Medium, which moved priority from 4 - Low to 3 - Moderate). The activity stream showed 7 entries.
Step 2: Export the record XML.
I exported the incident as XML. The file held more than the incident: 3 sys_journal_field rows (the work notes and comment), 1 sys_attachment row and 2 sys_attachment_doc rows (the file content). Every row links back to the incident's sys_id, directly or through the attachment record, so the record has to keep its original sys_id on the target. Importing the XML keeps it.
[Screenshots: XML file showing the journal and attachment rows]
Step 3: Import it into the target and check the activity stream.
On a second PDI, I imported the XML and opened the incident. The work notes, comment and attachment all came across with their original timestamps. But the activity stream showed 5 entries, not 7. Both field-change entries were missing.
The creation entry was also wrong. It showed Impact 2 - Medium, State In Progress and Priority 3 - Moderate. Those are the record's current values, not its values at creation (3 - Low, New, 4 - Low). With no sys_audit rows, the platform built the creation entry from what the record looks like now.
[Screenshot: target activity stream, 5 entries, wrong creation entry]
Step 4: Export and import the sys_audit rows.
On the source, I filtered sys_audit on Document key = the incident's sys_id. I also excluded work_notes and comments, because they already came with the record XML and I expected duplicates. That left 5 field-change rows. I exported them as XML and imported them into the target.
[Screenshot: sys_audit list on the target]
I reloaded the incident. Still 5 activities, and the creation entry was still wrong.
Step 5: Find out why the history didn't update.
sys_history_set had one row for the incident, created when I first opened the form in Step 3, before the audit rows existed. Its Last update recorded matched the incident's own last update (19:55:36). Importing sys_audit doesn't change the incident, so the platform saw no reason to rebuild.
→ please refer below screenshot
I deleted that row and reopened the incident. The history rebuilt and showed all 7 entries.
Refer below screenshot
Step 6: Do the journal audit rows cause duplicates?
To check whether the journal rows cause duplicates, I imported all 8 audit rows, including the 3 work_notes and comments rows, deleted the history set and reopened the form.
Still 7 activities. Each work note and comment appeared once, and the creation entry was correct: 3 - Low, New, 4 - Low. The activity stream takes journal entries from sys_journal_field and doesn't add them again from sys_audit. So no filter is needed. Export all audit rows for the record.
Two things I noticed while comparing:
- One activity entry can hold several audit rows. state and incident_state share the same record_checkpoint, so they show as one "Incident state" entry. Same for impact and priority.
- Not every audited field shows in the activity stream. urgency changed and has an audit row, but it isn't in the activity stream's field list on my instance. It didn't show on the source either, so don't treat that as a failed import.
The Method:
On the source:
- Export the record XML.
- Filter sys_audit on Document key = the record's sys_id and export it as XML.
On the target:
- Import the record XML.
- Import the sys_audit XML before anyone opens the record.
- If someone already opened it, delete the record's row in sys_history_set (filter on ID = sys_id).
- Open the record and compare the activity stream with the source.
Tested between two PDIs (an Australia release as the source and zurich as the Target)