Amazon Connect screenpop "create incident"

cogInWheel
Kilo Contributor

I'm trying to get servicenow to screenpop the Create Incident window when an agent receives a call but I'm stuck. The implementation comes with an operation handler to pop an interaction, but that's not what we're looking for. We want the agents to be able to immediately begin creating a ticket.

 

Does anyone have some suggestions? I've tried playing around with the operation handlers, script includes, and a client script but cannot seem to get it working. The operation handler I'm using creates the incident but the client script doesn't fire.

 

I'm lost.

 

Here's the client script I tried that was set to table: Incident [incident], UI type: desktop, type: onLoad, application: ServiceNow Voice.

function onLoad() {
    console.log("IncidentPop Client Script: Forcing the incident creation page to open.");
    window.open('/nav_to.do?uri=incident.do?sys_id=-1', '_blank');
}

 

Here's the operation handler - type: Script, Application: ServiceNow Voice, Domain: global

(function( /*CTIOperationRequest*/ request, /*CTIOperationResponse*/ response, /*Context*/ ctx) {

    try {
        // Use gs.info() instead of gs.log()
        gs.info("IncidentEvent Operation Handler: Triggered with sn_operation = " + request.getParameter('sn_operation'), "IncidentEvent");

        var state = request.getParameter('$state') || 'new';
        gs.info("IncidentEvent Operation Handler: State is " + state, "IncidentEvent");

        var phone = request.getParameter('contact.phone');
        var username = request.getParameter('contact.username');
        var someDataPresent = phone || username;

        if (!someDataPresent) {
            gs.error("IncidentEvent Operation Handler: Error - phone or username must be supplied.", "IncidentEvent");
            throw 'phone or username must be supplied';
        }
        gs.info("IncidentEvent Operation Handler: Phone = " + phone + ", Username = " + username, "IncidentEvent");

        // Create a new incident record
        var incidentGr = new GlideRecordSecure('incident');
        incidentGr.initialize();
        incidentGr.setValue('short_description', 'User Contact via Phone: ' + phone);
        incidentGr.setValue('caller_id', 'USER_NOT_FOUND'); // Default value if no user is found

        var incidentId = incidentGr.insert();
        gs.info("IncidentEvent Operation Handler: New incident created with sys_id = " + incidentId, "IncidentEvent");

        // Set session attributes to trigger the client script
        response.setSessionAttribute('sn_operation', 'incidentEvent');
        gs.info("IncidentEvent Operation Handler: Set session attribute sn_operation to 'incidentEvent'", "IncidentEvent");

        // Return success
        response.setStatusCode(200);
        response.setMessage('success');
        gs.info("IncidentEvent Operation Handler: Completed successfully.", "IncidentEvent");

    } catch (e) {
        // Log any errors that occur during script execution
        gs.error("IncidentEvent Operation Handler: Error occurred - " + e.message, "IncidentEvent");

        // Remove ctx.setError as it might not be available or necessary in this context
        // You can handle any required error propagation using a different method if needed
    }

})(request, response);

 

 

0 REPLIES 0