Snapshot provides Script Include APIs that can be used in places where you do server-side scripting in your ServiceNow instance. This way you can use Snapshot's functionality as part of your workflow such as creating a backup when a certain action occurs.
PerspectiumBackupRestore
The PerspectiumBackupRestore object provides a way to access the Snapshot configuration record and execute or restore backups.
To use this object, you first need to initialize it:
Initialize | Description |
new PerspectiumBackupRestore() | initializes PerspectiumBackupRestore |
Once initialized, you can reference the PerspectiumBackupRestore functions:
Methods | Description |
executeBackup(backup_gr) | pass a backup and restore GlideRecord to execute the backup. This will bulk share the records to be backed up in a cloud store |
refreshSnapshots() | calls to the Meshlet to refresh the available completed backups. This will remove restore type backup and restore records and replace them with new available backups to restore |
executeRestore(restore_gr) | calls to restore the record passed. It will automatically subscribe to the records from the backup and replace any records in the backup. |
createNotification(backup_gr) | create a notification for a when a backup is finished running. Notifications have a condition to trigger when the backup changes its status to “Complete”. The notification will email the users specified and the email will contain the name of the backup as well as the tables backed up. |
saveApplication(tables, name) | create a custom application template for quickly choosing tables to backup. |
Sample Code
Executing a backup
var pspBackup = new PerspectiumBackupRestore(); var bgr = new GlideRecord(‘u_psp_backup’); var backup_sys_id = <backup configuration record’s sys_id>; bgr.get(backup_sys_id); pspBackup.executeBackup(bgr);
Executing a restore
var pspBackup = new PerspectiumBackupRestore(); var rgr = new GlideRecord(‘u_psp_backup’); var restore_sys_id = <restore configuration record’s sys_id>; rgr.get(restore_sys_id); pspBackup.executeRestore(rgr);
Refreshing snapshots
var pspBackup = new PerspectiumBackupRestore(); pspBackup.refreshRestore();
Creating notifications
var pspBackup = new PerspectiumBackupRestore(); var bgr = new GlideRecord(‘u_psp_backup’); var backup_sys_id = <backup configuration record’s sys_id>; var who_to_notify = <comma separated emails/sys_id of users to be notified>; bgr.get(backup_sys_id); bgr.setValue(‘u_enable_notifications’, 1); bgr.setValue(‘u_users_to_notify’, who_to_notify) pspBackup.executeBackup(bgr);
Saving an application
var pspBackup = new PerspectiumBackupRestore(); var tables = <comma separated sys_ids of the tables>; var name = ‘Custom application’; pspBackup.saveApplication(tables, name);