Copying of fields from Parent Case record to Child Case record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 06:56 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 07:17 AM - edited 10-22-2024 07:19 AM
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
Thanks & Regards
Sejal Chavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 07:39 AM
Thank you so much for replying to me. So I followed the steps you mentioned.
I created a Script Include:
I created a Client Script:
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 07:47 AM - edited 10-22-2024 07:48 AM
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.
Thanks & Regards
Sejal Chavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 08:01 AM
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:
And updated it on the Client Script:
But same behavior, the fields are still not getting copied from parent to child.