How to override autopopulated field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 03:21 AM
Hi,
I am trying to auto populate 'Department' field based on BIA owner selected from sys_user table. For this I have created Onload and Onchange client scripts. i have additional requirement is if i ovveride Department value to any other value from the lookup for the same BIA owner on form , BIA form should get update with latest 'department' but in cmn_department table it should not be changed.
Can someone help on this.
OnLoad:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 03:44 AM
As per the requirement, department change should impact only on form/record. Could you please help on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 03:54 AM
your script is already working fine for fetching the department
ensure your onload script runs only for new record
function onLoad() {
if (g_form.isNewRecord())
return;
var biaOwner = g_form.getValue('assigned_to');
if (!biaOwner) {
g_form.clearValue('department');
return;
}
// Same logic as before, but triggered on form load
g_form.getReference('assigned_to', function(userRecord) {
if (userRecord && userRecord.department) {
g_form.setValue('department', userRecord.department);
}
// else {
// g_form.clearValue('department');
// }
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2025 04:08 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
