- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 10:23 PM
Hello ServiceNow experts!
I have created the below Client Script which is working as expected and this is because the 'Parent' field is on the Case form.
function onLoad() {
// Check if the form is a new record
if (g_form.isNewRecord()) {
// Clear the confirmation flags for new cases
sessionStorage.removeItem('confirmationShown');
sessionStorage.removeItem('descriptionConfirmationShown');
var parentId = g_form.getValue('parent');
// Show confirmation for short description if not already shown
var confirmationShown = sessionStorage.getItem('confirmationShown');
if (parentId && !confirmationShown) {
var answer = confirm("Do you want to copy the short description from the parent case?");
if (answer) {
var ga = new GlideAjax('GetParentFields');
ga.addParam('sysparm_name', 'getShortDescription');
ga.addParam('sysparm_parent_id', parentId);
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('short_description', response);
}
});
}
sessionStorage.setItem('confirmationShown', 'true');
}
// Show confirmation for description if not already shown
var descriptionConfirmationShown = sessionStorage.getItem('descriptionConfirmationShown');
if (parentId && !descriptionConfirmationShown) {
var descriptionAnswer = confirm("Do you want to copy the description from the parent case?");
if (descriptionAnswer) {
var gaDesc = new GlideAjax('GetParentFields');
gaDesc.addParam('sysparm_name', 'getDescription');
gaDesc.addParam('sysparm_parent_id', parentId);
gaDesc.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('description', response);
}
});
}
sessionStorage.setItem('descriptionConfirmationShown', 'true');
}
}
}
However, this 'Parent' field is not originally on the form.
The Client Script is just working because I have added it.
If I remove this field the Client Script will not execute properly.
Please help on what to replace on the line: var parentId = g_form.getValue('parent');
So that it will still execute even if the Parent field is not on the form.
Solved! Go to Solution.
- 593 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2024 12:17 AM
Hi @tindiz ,
One line of change you can do like below.
return parentGR.parent.short_description;
In both function just return "return parentGR.parent.short_description;" and from client script just pass current sys_id.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2024 12:53 AM
Please ignore my last reply. It did work now! Thank you soooo much!!!!!!!!!!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2024 12:59 AM
for some reason, I don't know if it's a system glitch but sometimes it work, sometimes not. If I try to create a child case from a child case, it doesn't work...