I want to copy short description and description of parent whenever we click on new child incident?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2025 01:38 AM
Hi Team,
After parent is getting created we are clicking on new child record,
and when we click on new it should fetch parent short_des and Description.
Can anyone help me in this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2025 02:12 AM
Please close your earlier asked questions as answered if solution worked for you.
Members have invested their time and efforts in helping you.
Marking answer as correct also helps future members
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2025 02:58 AM
Hi @Prathamesh Chav,
You may try with following code.
Client script:
function onLoad() {
if (g_form.getValue("parent_incident") != null) {
var ga = new GlideAjax('Include_to_populate_child_value'); // Script Include name
ga.addParam('sysparm_name', 'childinfo'); //fucntion name
ga.addParam('sysparm_parent_sys_id', g_form.getValue("parent_incident")); //parent sys_id
ga.getXML(parentinfo);
function parentinfo(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
try {
var returneddata = JSON.parse(answer);
g_form.setValue("description", returneddata.description);
g_form.setValue("short_description", returneddata.short_description);
} catch (e) {
alert('Error parsing the response: ' + e.message);
}
}
}
}
}
Script include:
var Include_to_populate_child_value = Class.create();
Include_to_populate_child_value.prototype = Object.extendsObject(AbstractAjaxProcessor, {
childinfo: function() {
var parentSysId = this.getParameter('sysparm_parent_sys_id'); // Get parent_sys_id parameter
var parentIncident = new GlideRecord('incident');
if (parentIncident.get(parentSysId)) {
var response = {
"description": parentIncident.description + "",
"short_description": parentIncident.short_description + ""
};
var jsonResponse = JSON.stringify(response);
return jsonResponse;
}
return '';
}
});
Please mark my response as correct and helpful if it helped solved your question.
Thanks,
Rohit Suryawanshi