Prepopulate the fields while creating child case

Manisha30
Tera Guru

Hi All,

 

We have a requirement to prepopulate the opened for with parent Assigned to field while trying to create a child HR case from HR Agent Workspace.

Tried creating a Business rule before insert, but it is happening after creating the case not while creating or while loading. 

 

Can someone provide your expertise over here?

 

Thanks in Advance!!!

Manisha

5 REPLIES 5

Ankur Bawiskar
Tera Patron

@Manisha30 

you can use onLoad client script, grab the sysId of parent

Then use GlideAjax to check the parent assigned to and set in Child HR Case

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hi @Ankur Bawiskar ,

 

Thanks for the quick response.

 

I did try with onchange client script as our requirement is specific to HR Service, when trying to create child case and hr service selected is "A", then the opened for should be prepopulated with Assigned to of Parent case, but no luck.

 

Thanks,

@Manisha30 

you want it while loading then why onchange script is required?

share your script and did you follow the approach I shared?

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

@Ankur Bawiskar Apologies, i have tried using onload client script but no luck, its not pre-populating the field value of opened for with assigend to of parent.

 

Client script:

 

function onLoad() {
    //Type appropriate comment here, and begin script below

    var hrServiceASysId = 'xxxxxxxx';
    var currentHrService = g_form.getValue('hr_service');
var parentCaseSysId = g_form.getValue('parent');
     if (parentCaseSysId && currentHrService == hrServiceASysId) {
        var ga = new GlideAjax('ChildCasePrepopulationUtils');
        ga.addParam('sysparm_name', 'getParentAssignedTo');
        ga.addParam('sysparm_parent_sys_id', parentCaseSysId);
        ga.getXML(updatechildcase);

        function updatechildcase(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            if (answer) {
                g_form.setValue('opened_for', answer);
            }
        }
    }

}

Script include:
 
var ChildCasePrepopulationUtils = Class.create();
ChildCasePrepopulationUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getParentAssignedTo: function() {
           var parentSysId = this.getParameter('sysparm_parent_sys_id');
           if (parentSysId) {
               var grParentCase = new GlideRecord('sn_hr_core_case');
               if (grParentCase.get(parentSysId)) {
                   return grParentCase.assigned_to.toString();
               }
           }
           return '';
       },

    type: 'ChildCasePrepopulationUtils'
});