Customizing Prefill Fields When Copying Records
Overview
The copy action on the record view allows for users to duplicate records. This article will cover the various ways to customize the prefill fields on the copy view.
Modifying the Copy Prefill View Using the Vardefs
The following section will outline how to modify the fields that are prefilled when copying a Bug record from the record view using the beans Vardefs. This is helpful when the list of copied fields are static and have no dependencies. You can apply this to any module in the system.
./custom/Extension/modules/Bugs/Ext/Vardefs/copyPrefill.php
<?php
//remove a field from copy
$dictionary['Bug']['fields']['description']['duplicate_on_record_copy'] = 'no';
//add a field to copy
$dictionary['Bug']['fields']['priority']['duplicate_on_record_copy'] = 'always';
Once in place, navigate to Admin > Repair > Quick Repair & Rebuild.
Note: You can name the file 'copyPrefill.php' anything you like. We advise against making these changes in the ./custom/Extension/modules/<module>/Ext/Vardefs/sugarfield_<field>.php
files as these changes may be removed during studio edits.
Modifying the Copy Prefill View Using JavaScript Controllers
The following section will outline how to modify the fields that are prefilled when copying a Bug record from the record view using the JavaScript Controller. This is helpful when you need to dependently determine the fields to copy by a field on the bean. You can apply this to any module in the system.
./custom/modules/Bugs/clients/base/views/record/record.js
({
extendsFrom: 'RecordView',
setupDuplicateFields: function (prefill) {
this._super('setupDuplicateFields', prefill);
var fields = [
'name',
'assigned_user_id',
'priority',
'type',
'product_category',
'description'
];
//determines whether the field list above is a set of allowlisted (allowed) or denylisted (denied) fields
var denylist = false;
if (denylist) {
_.each(fields, function (field) {
if (field && prefill.has(field)) {
//set denylist field to the default value if exists
if (!_.isUndefined(prefill.fields[field]) && !_.isUndefined(prefill.fields[field].default)) {
prefill.set(field, prefill.fields[field].default);
} else {
prefill.unset(field);
}
}
});
} else {
_.each(prefill.fields, function (value, field) {
if (!_.contains(fields, field)) {
if (!_.isUndefined(prefill.fields[field].default)) {
prefill.set(field, prefill.fields[field].default);
} else {
prefill.unset(field);
}
}
});
}
}
})
Once in place, navigate to Admin > Repair > Quick Repair & Rebuild. The denylist
variable will determine whether the list of fields are allowlisted or denylisted from the copy feature.