- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 08:34 AM
Hi Team,
A recurring issue in our environment is something will have the Case [sn_customerservice_case] table filtered to 'assigned_to' IS "[X]" or 'Account'//'Company' IS "[Y]" , and then they will click the [NEW] UI action button on the Case table to draft a new record --- the defined filtered logic I mentioned above will carry over onto the draft Case record [i.e. draft Case record 'Assigned To' will populate as "[X]" and/or 'Account' field will populate as "[Y]" --- therefore certain client scripts will not trigger correctly due to this.
I've attached two pairs of snips to demonstrate this behavior.
Can anyone recommend to me an efficient and low-resource way to ensure that OnCreate every single field value on a draft Case record is purged ? I see this as the simplest / best way to handle this.
Thanks,
Pat
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 04:07 AM
Hi @PB7 ,
To ensure that all field values are cleared when creating a new record (OnCreate), you can use an "OnBefore" business rule. Here's an example of a simple server-side script that you can use:
(function executeRule(current, previous /*null when async*/) {
// This business rule runs before the record is inserted.
// Check if the record is new (OnCreate)
if (current.isNewRecord()) {
// Loop through each field on the current record
for (var field in current) {
// Exclude system fields and fields you want to preserve
if (current[field] !== undefined && !field.startsWith('sys_') && field !== 'assigned_to' && field !== 'account') {
// Clear the field value
current[field] = '';
}
}
}
})(current, previous);
This script does the following:
- Checks if the record is new.
- Loops through each field on the current record.
- Excludes system fields (those starting with 'sys_'), and fields like 'assigned_to' and 'account' that you want to preserve.
- Clears the value for each field.
Make sure to adjust the fields you want to preserve in the exclusion list (field !== 'assigned_to' && field !== 'account'
), and you can add more fields as needed.
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 04:07 AM
Hi @PB7 ,
To ensure that all field values are cleared when creating a new record (OnCreate), you can use an "OnBefore" business rule. Here's an example of a simple server-side script that you can use:
(function executeRule(current, previous /*null when async*/) {
// This business rule runs before the record is inserted.
// Check if the record is new (OnCreate)
if (current.isNewRecord()) {
// Loop through each field on the current record
for (var field in current) {
// Exclude system fields and fields you want to preserve
if (current[field] !== undefined && !field.startsWith('sys_') && field !== 'assigned_to' && field !== 'account') {
// Clear the field value
current[field] = '';
}
}
}
})(current, previous);
This script does the following:
- Checks if the record is new.
- Loops through each field on the current record.
- Excludes system fields (those starting with 'sys_'), and fields like 'assigned_to' and 'account' that you want to preserve.
- Clears the value for each field.
Make sure to adjust the fields you want to preserve in the exclusion list (field !== 'assigned_to' && field !== 'account'
), and you can add more fields as needed.
Thanks,
Ratnakar