Pasting screenshots into requests or incidents

jpitts
Mega Contributor


Is it possible to take a screenshot of a users PC and paste it straight into the incident you are currently working on so it can be escalated with detail and efficiency? Or, does it require the first level technician to take the screenshot, save it on their PC locally then attach the screenshot as an attachment to the incident? Just looking for ways to reduce clicks and wasted processes.

 

thanks

1 ACCEPTED SOLUTION

Kamini Kansal
ServiceNow Employee
ServiceNow Employee

Hi Everyone,

This content-related to "Attach screenshots to incident from clipboard" can be found here:

https://developer.servicenow.com/app.do#!/share/contents/8639543_attach_screenshots_to_incident_from...

 

Regards,

Kamini Kansal

View solution in original post

15 REPLIES 15

Ian Catley
Tera Contributor

I realise this is a very old thread but I just came across the need to implement this and wanted to do so without adding a Chrome extension. Here is the code I used:

UI Action (Form button,Client) Script:

 

function clickIt() {
    var readImage = false;
    var postedMsg = false;
    var foundImage = false;
    try {
        navigator.clipboard.read().then(function(clipboardItems) {
            for (var i = 0; i < clipboardItems.length && !foundImage; i++) {
                for (var j = 0; j < clipboardItems[i].types.length; j++) {
                    if (clipboardItems[i].types[j].startsWith('image')) {
                        foundImage = true;
                        clipboardItems[i].getType(clipboardItems[i].types[j]).then(function(imageBlob) {
                            var reader = new FileReader();
                            reader.readAsDataURL(imageBlob);
                            reader.onloadend = function() {
                                var content = reader.result;
                                var ga = new GlideAjax('EPOaddScreenshot');
                                ga.addParam('sysparm_name', 'addScreenshot');
                                ga.addParam('sysparm_task', g_form.getUniqueValue());
                                ga.addParam('sysparm_content', content);
                                ga.addParam('sysparm_contentType', imageBlob.type);
                                ga.getXMLAnswer(function processResponse(serverResponse) {
                                    readImage = true;
                                    location.reload(true);
                                });
                            };
                        }); // end getType().then
                        break;
                    }
                }
            }
            if (!foundImage) {
                noImage();
            }
        }); // end read().then
        setTimeout(function() {
            if (!readImage) {
                noImage();
            }
        }, 3000);
    } catch (err) {
        g_form.addErrorMessage('Err:' + err.name + err.message);
    }

    function noImage() {
        if (!postedMsg) {
            postedMsg = true;
            g_form.addInfoMessage('No image found on the clipboard to paste');
        }
    }
}

Script Include EPOaddScreenshot
var EPOaddScreenshot = Class.create();
EPOaddScreenshot.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    addScreenshot: function() {
        var StringUtil = GlideStringUtil;
        var task = this.getParameter('sysparm_task');
        var base64Encodedcontent = this.getParameter('sysparm_content');
        var contentType = this.getParameter('sysparm_contentType');
        var grTask = new GlideRecord('task');
        var base64Header = 'data:' + contentType + ';base64,';
        if (base64Encodedcontent.startsWith(base64Header) && grTask.get(task)) {
            var grSpecific = new GlideRecord(grTask.sys_class_name);
            if (grSpecific.get(task)) {
                var gd = new GlideDateTime();
                var fileName = 'screenshot_' + gd.getLocalDate().getByFormat('yyyyMMdd') + '_' +
                    gd.getLocalTime().getByFormat('HHmmss') + getExtension(contentType);
                var attachment = new GlideSysAttachment();
                binData = StringUtil.base64DecodeAsBytes(base64Encodedcontent.replace(base64Header, ''));
                var sysId = attachment.write(grSpecific, fileName, contentType, binData);
                return sysId;
            }
        }
        return '';

        function getExtension(contentType) {
            if (contentType.toString() == 'image/png') { // This is the main thing we are expecting
                return '.png';
            }
            return '';
        }
    },

    type: 'EPOaddScreenshot'
});