logo

NJP

Passing variables from interaction records to record producers in agent workspace

Import · Oct 19, 2020 · article

I thought I'd share my solution to passing variables from interaction records to record producers in agent workspace as I struggled to find any solutions that worked for my requirements.

I have been tasked with configuring agent workspace to pass variables to the incident and a general request (record producer) form from interaction records. The idea is that Service Desk staff will use the interaction record for first contact with a customer and then spawn an incident or general request based on the content of their interaction.

To pass variables to the incident form was easy enough and just required a couple more lines to the existing UI Action. The general request was not so easy as the out of the box request UI Action couldn't pass variables directly to the record producer. I'm pretty sure I looked at every article and how-to guide out there but none of the options presented were working for me.

In the end, I used parts of this ServiceNow Guru article to assist in sending/receiving parameters to/from the URL and then created custom regex filters to pull out the 3 variables I required. The URL in agent workspace is not formatted like non-agent workspace URL's in ServiceNow so the standard ways of obtaining the parameters did not work. Here's the code for how I got it all working:

UI Action: Workspace Client Script

function onClick() {


var result = g_form.submit('sysverb_ws_save');
    if (!result) { 
        return;
    }
    result.then(function() {
        var params = {};
        params.sysparm_parent_table = "interaction";
        params.sysparm_parent_sys_id = g_form.getUniqueValue();
        params.sysparm_shortDescription = g_form.getValue('short_description');
        params.sysparm_caller = g_form.getValue('opened_for');
        params.sysparm_type = g_form.getValue('type');
        g_service_catalog.openCatalogItem('sc_cat_item', '471cd65f1bcf98100f7c982d0d4bcbe2', params); //Gets the record producer matching the sys_id
    });
}

Catalogue Client Script: OnLoad

function onLoad() {
    //Use the 'getParameterValue' function below to get the parameter values from the URL
    var url = top.document.URL;
    var shortDescPattern = new RegExp('(?<=description\/)(.*)(?=\/sysparm-caller)');
    var shortDesc = shortDescPattern.exec(url);
    if (shortDesc) {
        g_form.setValue('short_description', shortDesc[0]);
    }

    var callerPattern = new RegExp('(?<=sysparm-caller\/)(.*)(?=\/sysparm)');
    var caller = callerPattern.exec(url);
    if (caller) {
        g_form.setValue('requested_for', caller[0]);
    }

    var typePattern = new RegExp('(?<=sysparm-type\/)(.*)');
    var type = typePattern.exec(url);
    if (type) {
        g_form.setValue('contact_type', type[0]);
    }

}

This does require that the URL is formed in a specific way, but as long as you add additional variables to the end of the workspace client script, it shouldn't break any of the previous ones.

I hope this helps someone else out there image

Cheers,

Brad

View original source

https://www.servicenow.com/community/itsm-articles/passing-variables-from-interaction-records-to-record-producers/ta-p/2306598