How to get parent major case values to child case before clicking on the submit button

Gopal14
Tera Contributor

Hi Team,

 

How to get parent major case values to child case before clicking on the submit button.

 

Requirement:

On the major case form we have a related list called "child cases". After Clicking on the New button on the child cases case form will open. If we click on submit ui action, after form saves all the parent case values will capture in the child case, this is OOTB functionality.

 

But I want to populate parent case values, before submitting the child case form.

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Gopal14 On the create new case form, if you have access to the parent case (via a reference field) then you can create an onLoad script and use g_form.getReference to fetch all the details of the parent case and pre-populate them on the form using g_form.setValue().

Hi @Sandeep Rajput ,

 

Thanks for the help!

 

Can you please share me the code

Jitendra Diwak1
Kilo Sage

Hi @Gopal14,

 

This can be achieved like below code:

Create one Script Include:

 

var AutoFillData = Class.create();
AutoFillData.prototype = {
    initialize: function() {},

    autoFillData: function() {

        var syID = gs.getParameter('sysparm_sysID');
        var obj = {};
        var inc = new GlideRecord('incident');
        inc.addQuery('parent_incident', syID);
        inc.query();
        if (inc.next()) {
            obj.short_description = inc.short_description;
            obj.description = inc.description;
            return JSON.stringify(obj);
        }
    },

    type: 'AutoFillData'
};

 

 

Create onLoad Client script below:

 

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   var sysID = g_form.getUniqueValue();
   var inc = new GlideAjax('AutoFillData');
   inc.addParam('sysparm_name','autoFillData');
   inc.addParam('sysparm_sysID', sysID);
   inc.getXML(callBack);
   function callBack(response){
	var comments = response.responseXML.documentElement.getAttribute("answer");
	var data = JSON.parse(comments);
	g_form.setValue('short_description', data.short_description);
	g_form.setValue('description', data.description);
   }
}

 

 

Note: I have created this for parent child Incident. You can replace the table name in GlideRecord.

 

Please accept the solution if it works for you.

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.