How to preserve FIELDS ONLY (not entire table records) across Clone Operations?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:19 AM
Hello. We like to have different FavIcons on our Dev, Test, and Prod instances, so we don't get confused as to which instance we are working in. We like to have separate icons on the Portal pages as well.
For the Platform UI, we are able to Preserve system properties and thus preserve the icons across Clone operations.
But for the Portal, it seems like the Portal record has the images embedded in the Portal record itself as opposed to POINTING to the images.
I don't see any final solution in this article:
How can we preserve ONLY the following 2 fields out of the entire Portal record? The rest of the fields we DO want to be cloned down. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:45 AM
Hi @G24
unfortunately, it is not possible to break down preserving on field level.
I could imagine implementing a post-clone script which exchanges the icons on the target instance.
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:51 AM
Hi Geoffrey,
Data Preservers work on table records, there is no option to specify fields
Seem you will have to update those records in the target instance once the clone is complete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 08:52 AM
As others have mentioned, Clone Data Preservers will preserve an entire record and not individual fields.
However, the funny thing about the "Image" type field is they actually point to a record in the Attachment table [sys_attachment]. They are records, so we should be able to target them and setup a Clone Data Preserver to save them. Now, those records are saved a bit differently from "normal" attachments:
- "Table name" contains a prefix of "ZZ_YY" before the actual table name ("sp_portal" in this case)
- the "File name" is the name of the field ("icon" or "logo" in this case)
So a Clone Data Preserver could be setup to save the icon and logo Attachment records, but you would need a Clone Cleanup Script to relink them to the actual Portal records.
I don't have a setup I could try this with at the moment, but a script could loop through all the Portal [sp_portal] records and look to see if there is another Attachment record [sys_attachment] for that Portal that is not currently linked to the icon/logo field. Something like:
(function() {
var log = [];
var portal = new GlideRecord("sp_portal");
portal.query();
while (portal.next()) {
log.push(portal.getDisplayValue());
//look for an alternate icon attachment record
var attachment = new GlideRecord("sys_attachment");
attachment.addEncodedQuery("file_name=icon^table_name=ZZ_YYsp_portal^table_sys_id=" + portal.getValue("sys_id") + "^sys_id!=" + portal.getValue("icon"));
attachment.query();
//update the Portal record if we find another Attachment record
if (attachment.next()) {
log.push("...found an alternate icon attachment for " + portal.getDisplayValue());
portal.icon = attachment.getValue("sys_id");
portal.update();
}
//look for an alternate logo attachment record
var attachment = new GlideRecord("sys_attachment");
attachment.addEncodedQuery("file_name=logo^table_name=ZZ_YYsp_portal^table_sys_id=" + portal.getValue("sys_id") + "^sys_id!=" + portal.getValue("logo"));
attachment.query();
//update the Portal record if we find another Attachment record
if (attachment.next()) {
log.push("...found an alternate logo attachment for " + portal.getDisplayValue());
portal.logo = attachment.getValue("sys_id");
portal.update();
}
}
return log;
})();
Again, I don't have a setup to test the script properly with a clone, but I was able to flip the icon image back and forth between 2 attachments for a particular Portal record, so it seems like it would work. I setup an alternate Attachment record then ran the script in Xplore and it would flip the icon field between the two:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:29 PM - edited 09-04-2023 12:19 PM
Thanks @Jim Coyne and Others,
You helped me figure out the following solution:
Clone / Cloning - How to Preserve Service Portal Icon and Logo
In this case, because of the design of ServiceNow "Image" type fields, even preserving data at the Field level instead of the Record level would not be sufficient. Because the field does not actually contain anything. It basically just says "Go look in the sys_attachment table and see if anything is there". So the records that actually need to be preserved are in the sys_attachment and sys_attachment_doc tables. Thanks!