The CreatorCon Call for Content is officially open! Get started here.

Copy Case in Customer Portal

Servicenow Sava
Giga Contributor

When case is created in Customer Portal. I need a copy case functionality. When user clicks the Copy case in the customer portal then the selected fields values should be auto populated to Case creation form in customer portal. So that user can duplicate a case.

 

@Ankur Bawiskar @Indrajit 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Servicenow Sava 

there is nothing OOTB for this.

You will have to build a custom solution for this.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur Bawiskar,

 

I have created a Button " Copy Case" in the widget HTML . Below is the server script and client controller script.

if (input && input.action == 'copycase') {
    data.caseToCopy = {};

    var srcCase = new GlideRecord('x_igss2_customer_p_standard_case');
    if (srcCase.get(input.case_sys_id)) {

        // List of fields to copy (same as your UI Action)
        var fields = [
            'account','u_type_of_support','contact','u_partner','u_partner_contact',
            'internal_contact','sold_product','u_environment','version',
            'u_application_url','u_tenancy','priority','alternate_contact_name',
            'alternate_contact_email','u_alternate_contact_phone','short_description'
        ];

        for (var i = 0; i < fields.length; i++) {
            var f = fields[i];
            var val = srcCase.getValue(f);               // sys_id or value
            var disp = srcCase.getDisplayValue(f);      // readable label
            if (val && val !== 'undefined') {
                data.caseToCopy[f] = String(val);

                // For reference fields, also pass display value
                if (disp && disp !== '' && disp !== val) {
                    data.caseToCopy[f + '_display'] = String(disp);
Client Controller:
c.copycase = function() {
    c.server.get({
        action: 'copycase',
        case_sys_id: c.data.sys_id
    }).then(
        function(response) {
            if (response.data && response.data.caseToCopy) {
                var caseData = response.data.caseToCopy;

                var recordProducerSysId = '3db464c31b33111c08d497d8b04bcb4e';
                var url = '/csmcore?id=csm_get_help&sys_id=' + recordProducerSysId;

                // Append only valid fields
                for (var fieldName in caseData) {
                    if (caseData.hasOwnProperty(fieldName)) {
                        var value = caseData[fieldName];
                        if (value && value !== 'undefined') {
                            url += '&' + encodeURIComponent(fieldName) + '=' + encodeURIComponent(value);
                        }
                    }
                }

                window.location.href = url;
            } else {
                console.warn('copycase: no caseToCopy returned');
            }



Servicenow Sava
Giga Contributor

@Ankur Bawiskar 

 

Created a copy case button in widget HTML and below is the Server Script and Client Controller. But still the values are not been populated on Case creation form.

Client Controller:

c.copycase = function() {
    c.server.get({
        action: 'copycase',
        case_sys_id: c.data.sys_id
    }).then(
        function(response) {
            if (response.data && response.data.caseToCopy) {
                var caseData = response.data.caseToCopy;

                var recordProducerSysId = '3db464c31b33111c08d497d8b04bcb4e';
                var url = '/csmcore?id=csm_get_help&sys_id=' + recordProducerSysId;

                // Append only valid fields
                for (var fieldName in caseData) {
                    if (caseData.hasOwnProperty(fieldName)) {
                        var value = caseData[fieldName];
                        if (value && value !== 'undefined') {
                            url += '&' + encodeURIComponent(fieldName) + '=' + encodeURIComponent(value);
                        }
                    }
                }

                window.location.href = url;
            } else {
                console.warn('copycase: no caseToCopy returned');
            }
Server Script :
if (input && input.action == 'copycase') {
    data.caseToCopy = {};

    var srcCase = new GlideRecord('x_igss2_customer_p_standard_case');
    if (srcCase.get(input.case_sys_id)) {

        // List of fields to copy (same as your UI Action)
        var fields = [
            'account','u_type_of_support','contact','u_partner','u_partner_contact',
            'internal_contact','sold_product','u_environment','version',
            'u_application_url','u_tenancy','priority','alternate_contact_name',
            'alternate_contact_email','u_alternate_contact_phone','short_description'
        ];

        for (var i = 0; i < fields.length; i++) {
            var f = fields[i];
            var val = srcCase.getValue(f);               // sys_id or value
            var disp = srcCase.getDisplayValue(f);      // readable label
            if (val && val !== 'undefined') {
                data.caseToCopy[f] = String(val);

                // For reference fields, also pass display value
                if (disp && disp !== '' && disp !== val) {
                    data.caseToCopy[f + '_display'] = String(disp);
                }

@Servicenow Sava 

so what debugging did you do?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader