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

Copying of fields from Parent Case record to Child Case record

tindiz
Giga Guru
In the "sn_customerservice_case" table, the Case record features a Related List for Child Cases.
 

The goal is to ensure that when users click the "New" button on the Child Cases related list, the following fields from the Parent Case will be copied over to the Child Case by default:

 

correlation_id
category
account
contact
u_notes
contact_type
priority
assignment_group
attachments

 

And then there should be a pop-up message if they also would like to get the "short_description" and "description" to be copied as well as these are optional only. The question should be answerable by YES or NO. If they select YES then it will be copied over if NO then it should not.

 

Could you help me implement these requirements?

7 REPLIES 7

sejal1107
Tera Guru
Tera Guru

Hi @tindiz 

 

Please try below client script

 

function onLoad() {
    // Get the Parent Case sys_id from the URL parameters
    var parentSysId = g_form.getParameter('parent.sys_id');

    if (parentSysId) {
        // Create a GlideAjax object
        var ga = new GlideAjax('ParentCaseUtils');
        ga.addParam('sysparm_name', 'getParentCaseData');
        ga.addParam('sysparm_parent_sys_id', parentSysId);

        // Call the Script Include
        ga.getXMLAnswer(function(response) {
            var parentData = JSON.parse(response);
            
            // Copy mandatory fields
            g_form.setValue('correlation_id', parentData.correlation_id);
            g_form.setValue('category', parentData.category);
            g_form.setValue('account', parentData.account);
            g_form.setValue('contact', parentData.contact);
            g_form.setValue('u_notes', parentData.u_notes);
            g_form.setValue('contact_type', parentData.contact_type);
            g_form.setValue('priority', parentData.priority);
            g_form.setValue('assignment_group', parentData.assignment_group);
            
            // Ask user about optional fields
            var userResponse = confirm("Do you want to copy the short description and description from the parent case?");
            if (userResponse) {
                // If YES, copy optional fields
                g_form.setValue('short_description', parentData.short_description);
                g_form.setValue('description', parentData.description);
            }
        });
    }
}

 

  and script include 

 

var ParentCaseUtils = Class.create();
ParentCaseUtils.prototype = {
    initialize: function() {},
    
    getParentCaseData: function(parentSysId) {
        var result = {};
        var parentCase = new GlideRecord('sn_customerservice_case');
        if (parentCase.get(parentSysId)) {
            result.correlation_id = parentCase.correlation_id;
            result.category = parentCase.category;
            result.account = parentCase.account;
            result.contact = parentCase.contact;
            result.u_notes = parentCase.u_notes;
            result.contact_type = parentCase.contact_type;
            result.priority = parentCase.priority;
            result.assignment_group = parentCase.assignment_group;
            result.short_description = parentCase.short_description;
            result.description = parentCase.description;
        }
        return JSON.stringify(result);
    },

    type: 'ParentCaseUtils'
};

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers

Thanks,

Sejal

Please check and Mark Helpful and Correct if it really helped you.
Thanks & Regards
Sejal Chavan

Thank you so much for replying to me. So I followed the steps you mentioned.

I created a Script Include:

tindiz_0-1729607888814.png

I created a Client Script:

tindiz_1-1729607916715.png

 

I went to the Parent Case and click the "New" UI action on the Child Cases Related List however, none of the fields get copied over:

 

tindiz_2-1729607978341.png

 

sejal1107
Tera Guru
Tera Guru

hi @tindiz 

 

please remove everything from script include script and check the Client callable checkbox also make it accessible to all application scope

and then copy the code into the script

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. 

 

 

Please check and Mark Helpful and Correct if it really helped you.
Thanks & Regards
Sejal Chavan

So what I did is I deactivated the previous Script Include as it does not let me change the accessible from field and created one under Global application:

 

tindiz_0-1729609253572.png

And updated it on the Client Script:

 

tindiz_1-1729609288387.png

But same behavior, the fields are still not getting copied from parent to child.