Skip to content

Instantly share code, notes, and snippets.

@mtcoffee
Created October 29, 2023 23:57
Show Gist options
  • Select an option

  • Save mtcoffee/d26b96832e31cd65656d8df4da2d9d75 to your computer and use it in GitHub Desktop.

Select an option

Save mtcoffee/d26b96832e31cd65656d8df4da2d9d75 to your computer and use it in GitHub Desktop.
Set Name and Clone date in ServiceNow Banner
// Create an SVG string
var currentDate = new GlideDate();
var instanceName = gs.getProperty('instance_name');
var svgContent = '<svg width="550" height="100" xmlns="http://www.w3.org/2000/svg">' +
'<text x="20" y="50" style="font-family: Arial; font-weight: bold; font-size: 60; fill: #ffffff;">' + instanceName + '</text>' +
'<text x="20" y="90" style="font-family: Arial; font-size: 40; fill: #ffffff;">Cloned ' + currentDate + '</text>' +
'</svg>';
// Run functions to create an image and set it as the logo
var imageFileName = createImageRecord(svgContent);
setImageAsLogo(imageFileName);
function createImageRecord(svgData) {
// Set a name for the image file
var randomNumber = Math.floor(Math.random() * 100); // To avoid possible collisions
var imageName = 'instanceLogo' + randomNumber + currentDate + '.svg';
// Create a new empty db_image record to store the graphic
var rec = new GlideRecord("db_image");
rec.initialize();
rec.name = imageName;
rec.format = "svg";
rec.category = 'general';
rec.insert();
// Create a new attachment record
var attachment = new GlideSysAttachment();
// Set the attachment file name and content type
var fileName = 'generated.svg';
var contentType = 'image/svg+xml';
// Set the attachment content
attachment.write(rec, fileName, contentType, svgData);
// Insert the attachment record and link it to db_image
attachment.insert();
// Get the new attachment sys_id so we can set the "db_image.image" field to the attachment sys_id
var attach = new GlideRecord("sys_attachment");
attach.get('table_sys_id', rec.sys_id);
rec.image = attach.sys_id;
rec.update();
return imageName;
}
function setImageAsLogo(imageName) {
// Update the property to point to our db_image record
gs.setProperty('glide.product.image.light', imageName);
var rec = new GlideRecord('sys_properties');
rec.get('name', 'glide.product.image.light');
rec.setValue('type', 'image');
rec.update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment