Copy Service Request

anbu2
Kilo Explorer

Hi All, I'm trying here to copy the existing service request to create a new one. Once the 'Copy' option is selected, it should not automatically create the new ticket, it should just bring the user to a new form with all of the same user-input fields copied (SD, Description, any other RITM-specific catalog variables);   the user should still be required to review the form and submit (and have the capability to add a new attachment, since any old attachments will not carry over) I also had a chance to try the OOB functionality but that doesn't suit my requirement i would like a "Copy" feature to be specific.

21 REPLIES 21

kutvaram
Tera Expert

Hi,

Did you got the solution for this requirement?

If so, Can you please share it here.

Thanks,

Ram Prakash K R

Patricio Javier
Tera Contributor
var current = true;
var companyID = 'fcd19d891b7ff010f6f1c952604bcbca';


var scRequestItem = new GlideRecord('sc_request_item');
var scTask = new GlideRecord('sc_task');
var countTo = 5;

var glide = 'sc_request';
var query = 'number=REQ0020755';

var scRequest = new GlideRecord('sc_request');
scRequest.addEncodedQuery(query);
scRequest.query();
if (scRequest.next()) {

    for (var i = 0; i < countTo; i++) {
        try {
            var glideRequest = new GlideRecord('sc_request');
            glideRequest.initialize();
            glideRequest = scRequest;
            glideRequest.number = '';
            glideRequest.sys_id = '';
            glideRequest.insert();

            query = 'request=be190f8e1b5ef910f6f1c952604bcb22';

            try {
                var scRequestItem = new GlideRecord('sc_req_item');
                scRequestItem.addEncodedQuery(query);
                scRequestItem.query();
                while (scRequestItem.next()) {
                    var glideRequestItem = new GlideRecord('sc_req_item');
                    glideRequestItem.initialize();
                    glideRequestItem = scRequestItem;
                    glideRequestItem.request = glideRequest.sys_id;
                    glideRequestItem.number = '';
                    glideRequestItem.sys_id = '';
                    glideRequestItem.insert();
                    gs.print(glideRequestItem.number);

                    query = 'request_item=76190f8e1b5ef910f6f1c952604bcb23^';

                    try {
                        var scTask = new GlideRecord('sc_task');
                        scTask.addEncodedQuery(query);
                        scTask.query();
                        while (scTask.next()) {
                            var glideTask = new GlideRecord('sc_task');
                            glideTask.initialize();
                            glideTask = scTask; 
                            glideTask.request_item = glideRequestItem.sys_id;
                            glideTask.number = '';
                            glideTask.sys_id = '';
                            glideTask.insert();
                            gs.print(glideTask.number);
            
                        }
                    } catch (e) {
                        var message = e.message;
                        gs.log(message, '[SC Task ]');
                    }    
                }
            } catch (e) {
                var message = e.message;
                gs.log(message, '[SC REQ ITEM ]');
            }

        } catch (ex) {
            var message = ex.message;
            gs.log(message, '[SC REQUEST ]');
        }

    }

}