Create Case parent case and child case when the state is closed or cancelled on same UI ID.

Mannam Praveen
Tera Expert

I have requirement to create parent case and child case when existing case with same UI D is closed or cancelled. I using below script. but it is not working

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    //Check record exists for the given u_id
    var gr_case = new GlideRecord('x_att12_engage_now_engage_case');
    gr_case.addQuery('correlation_id', source.getValue('u_id'));
    gr_case.addQuery('state', 'IN', '1,10,18');
    gr_case.query();
    //If there is a existing CASE with OPEN status then do not create NEW case send the existing CASE id
    if (gr_case.next()) {
        response.status_message = "CASE " + gr_case.number + " already exists in SNOW with OPEN state for the given TICKET : " + source.getValue('u_id');
        ignore = true;
    }
    this.parent_id = '';
    if (source.getValue('u_customer_id') != null) {
        var cc_gr = new GlideRecord('customer_account');
        cc_gr.addQuery('account_code', source.getValue('u_customer_id'));
        cc_gr.query();
        var cc_sys_id = '';

        if (cc_gr.next()) {
            cc_sys_id = cc_gr.sys_id;
        }

        if (cc_sys_id != '') {

            var egr = new GlideRecord('x_att12_engage_now_engage_case');
            egr.addEncodedQuery('parent=NULL^state!=3^short_description=NULL^account=' + cc_sys_id);
            egr.query();

            if (!egr.next()) {

                egr.initialize();
                egr.setValue('contact_type', 'otis');
                this.parent_id = egr.insert();

            } else {
                this.parent_id = egr.getValue('sys_id');

            }
        }
    }

})(source, map, log, target);

 

0 REPLIES 0