I’m looking for some advice for moving documents from one Citizen Hub host to another.
One of the hosts is being decommissioned, with the service forms being moved to another, along with the data.
The “Documents” object records contain physical files that need to be moved.
With an export and import template, I can’t import files, even if converted into Base 64 format.
With an API call from one host to another, I can create the CASE record and using new TEMP messages and documents objects I can store properties like file name, and the base64 content string.
When a new record is added to the temp documents object I’m then trying to use a code studio action to initiate a new file, then use the cs.write_file() function to convert the Base64 string into the file.
The problem I’m having is I can’t get as far as writing the file, as the filename is an attribute, and not a property, so I can’t write to it.
// Create new file object
var newFile = cs.save(cs.ref("obj_documents"), {
':id': null,
'field_document_filename' : fileName
});
// Add relationship to case
var newFileID = newFile.records.base.record_id;
if(typeof newFileID === 'number' && newFileID > 0)
{
caseRecord.set(cs.ref('relpath_case_to_documents') + ':id' , newFileID );
}
let write_result = cs.write_file(newFileID , cs.ref("field_document_content_file"), fileName, base64Content);
Any thoughts on other ways to do this, or if there is a workaround to initiate a new Documents object record and pass attributes to it?
Another idea I had was setting up remote object connections for the “Messages” and “Documents” objects from the old host to the new one, then letting all data synch over.
Then store temporarily the IDs of Documents and Messages against the CASE and using the remote IDs to relate to those in the remote object.
Then sever the remote object connections so they become local objects.
Then running further rules and signals to move from the temporary Messages and Documents objects to the actual ones (copying the relationships).
It’s quite a long winded approach and I don’t know if the email content files and document files actually synch in remote objects.
The Filename Attribute should be writable, as is the File Attribute itself. Although I’ve not tried this from Code Studio, but not aware it should be any different.
Thanks Bob.
It is working for documents.
I’m still struggling with messages though, to write email content files. I can’t set attributes like email subject or email recipient. These throw errors like “Cannot set the attribute ‘email_recipient_email_address’”. Is there a way around this or another way to move the emails?
Code for messages:
main: function(record_id, parameters, rule) {
let tempMessage = cs.record(record_id);
let recipient = tempMessage.get(cs.ref('field_temp_message_recipient'));
let base64Content = tempMessage.get(cs.ref('field_temp_message_base64_content'));
let emailContent = tempMessage.get(cs.ref('field_temp_message_content_text'));
let emailSubject = tempMessage.get(cs.ref('field_temp_message_subject'));
let caseID = tempMessage.get(cs.ref('field_temp_message_case_id'));
let caseRecord = cs.record(caseID);
// Create new messages object
// ISSUE - can't write to attributes
var newMessage = cs.save(cs.ref("obj_message"), {
':id': null,
'field_message_recipient' : recipient,
'field_message_subject' : emailSubject,
'field_message_email_content_text' : emailContent
});
// Add relationship to case
var newMessageID = newMessage.records.base.record_id;
if(typeof newMessageID === 'number' && newMessageID > 0)
{
caseRecord.set(cs.ref('relpath_case_to_messages') + ':id' , newMessageID);
}
var write_result = cs.write_file(newMessageID, cs.ref("field_message_email_content_file"), "email.eml", base64Content);
}
Code for documents for anyone looking for similar.
main: function(record_id, parameters, rule) {
let tempFile = cs.record(record_id);
let filename = tempFile.get(cs.ref('field_temp_document_filename'));
let base64Content = tempFile.get(cs.ref('field_temp_document_base64_content'));
let caseID = tempFile.get(cs.ref('field_temp_document_case_id'));
let caseRecord = cs.record(caseID);
// Create new file object
var newFile = cs.save(cs.ref("obj_documents"), {
':id': null,
'field_document_filename' : filename
});
// Add relationship to case
var newFileID = newFile.records.base.record_id;
if(typeof newFileID === 'number' && newFileID > 0)
{
caseRecord.set(cs.ref('relpath_case_to_documents') + ':id' , newFileID);
}
var write_result = cs.write_file(newFileID, cs.ref("field_document_file"), filename, base64Content, {base64: true});
}
}
As Message records are a record of what was sent/received by Create, their creation and most of their Attributes cannot be manipulated directly. I don’t think there will be a way to spoof the creation of Message records via Code Studio unfortunately.
By the way, within Data Store > Objects if you go into a specific Object and look at the Attributes tab, it will show you which are editable. For message Objects the vast majority will not be editable.
Thanks Bob.
That is useful to know about the editable column on attributes.
With messages I will probably have to go down the remote object route in that case, and then see if they can then be transferred from one object to another - then relinked up to the right cases.
Unfortunately I don’t think Remote Objects will be usable for this either. Remote objects only sync the Properties and on the downstream app will appear as a a General type Object (not a Messages type Object). So they won’t have all the Message Attributes which make up the bulk of the info you probably want to copy.
I think you would need to use General objects for your copy of Messages, creating Properties for all the source Attributes you want to keep. This will allow you to copy the data in, but they won’t act the same as native Message records on the destination app, e.g. you won’t be able to use them in the Messaging widget. But you can still view them via normal List and Info widgets for example.
1 Like