Copy incident with form variables to new incident

Bret Smith
Giga Guru

When I copy an Incident with form variable the variables are not being copied to the new incident

 

Original

BretSmith_0-1729106857470.png

 

Newly copied Incident

BretSmith_1-1729106892272.png

 

 

 

6 REPLIES 6

Bert_c1
Kilo Patron

You will need to post more information I believe to get assistance here.

 

tips-on-asking-question-on-community

 

How are you copying an incident.  You'll need to include the records in the 'sc_item_variables_task' table where 'task' contains the sys_id of the incident.

Using the Copy Incident 

BretSmith_0-1729112724886.png

 

Bert_c1
Kilo Patron

I see that the OOB UI action named 'Copy Incident' that it references code in the 'IncidentUtils2' script include, and that extends the 'IncidentUtils2SNC' script include.  And in there is the 'copyIncidentRelatedLists' method that I believe should work, include the records in the 'sc_item_variables_task' for the incident.  You could override the method to add logic to copy records in the sc_item_variables_task table.

 

However, I see there that there is a system property named "com.snc.incident.copy.related_lists", and I see OOB that the 

"sc_item_variables_task" table is not shown there. Add that table in the Value there, see below
 
Screenshot 2024-10-16 181518.png

 How/where do I add the records in the 'sc_item_variables_task' for the incident. 

 

function OnCopyIncidentClick(){
    var srcSysId = g_form.getUniqueValue();
    var ga = new GlideAjax('IncidentUtils2');
    ga.addParam('sysparm_name', 'getIncidentQueryParams');
    ga.addParam('sysparm_src_sysid', srcSysId);
    ga.addParam('sysparm_ui_action', "copy_incident");
    ga.setWantSessionMessages(true);
    ga.getXMLAnswer(function(queryParam){
        if (queryParam) {
            var ck;
            if (typeof g_ck != 'undefined' && g_ck != "")
                ck = g_ck;

            var gotoUrl = [];
            gotoUrl.push('srcSysID=' + srcSysId);
            gotoUrl.push('newSysID=$sys_id');
            gotoUrl.push('sysparm_returned_action=$action');
            gotoUrl.push('sysparm_ui_action=copy_incident');
            if (ck)
                gotoUrl.push('sysparm_ck=' + ck);

            gotoUrl = 'CopyIncidentRelatedLists.do?' + gotoUrl.join('&');

            var form = cel('form', document.body);
            hide(form);
            form.method = "POST";
            form.action = g_form.getTableName() + ".do";
            if (ck)
                addParam(form, 'sysparm_ck', g_ck);
            addParam(form, 'sys_id', '-1');
            addParam(form, 'sysparm_query', queryParam);
            addParam(form, 'sysparm_goto_url', gotoUrl);
            form.submit();
        }else{
            g_form.addErrorMessage("Failed to copy incident");
        }
    });
}
function addParam(form, name, val) {
    var inp = cel('textarea', form);
    inp.name = name;
    inp.value = val;
}