|
// 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(); |
|
} |