Make values read only in the List type field which has drop downs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 03:39 AM - edited 06-07-2024 04:20 AM
Hello, @Amit Gujarathi @Ankur Bawiskar @Community Alums @Abhinay Erra @shloke04
I have a tricky requirement is it possible to make specific values READ only in the choice field.
Example: List field is "Versions" with below drop down values:
London
Kingston
Madrid
New York
Orlando
Paris
Rome
Here by default we set values (London & Paris) in the field. Now these 2 values shouldn't be removed/edited but I should be able to select another values in the field.
Is it possible? If yes, please share your suggestions.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 04:00 AM
Hi @Ksnow,
By following anyone of two options we can achieve your requirment.
Case 1:
If you want to restrict the values of the field to be edited on the list we can control this by using List Control from the list view of the records. This will not allow to edit any of the fields from the list. Please follow below steps to restrict update of fields on list.
Open list of records --> using column options select 'LIST CONTROL' --> select 'List Edit Type' as 'Disable list editing'
Case 2:
If you want to restrict edit only the specific field on the list as per your condition, you need to write ACL.
steps to achieve:
1. Elevate your role as Security Admin
2. Create ACL with Type as Record; Operation as list_edit; followed by your table name, column(field) name with respective Roles and Condition (you can use scripting to achieve your requirement).
By creating an ACL you can restrict the editing of the field on the list view for the role and as per the condition.
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 04:23 AM
Hi @Ksnow
Create Client Script to Prevent Removal of Default Values
Create a client script to ensure that "London" and "Paris" cannot be removed from the selected values.
**Configure the Client Script:**
- **Name:** Prevent Removal of Default Versions
- **Table:** The table containing the "Versions" field.
- **Type:** onChange
- **Field:** Versions
- **Condition:** Leave it blank to always run the script.
**Script:**
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Default values that should not be removed
var defaultValues = ['London', 'Paris'];
// Get the current values of the Versions field
var currentValues = g_form.getValue('versions').split(',');
// Ensure default values are always present
var updatedValues = [];
for (var i = 0; i < defaultValues.length; i++) {
if (currentValues.indexOf(defaultValues[i]) === -1) {
updatedValues.push(defaultValues[i]);
}
}
// Merge default values with current values
updatedValues = updatedValues.concat(currentValues);
// Remove duplicates
var uniqueValues = [];
for (var j = 0; j < updatedValues.length; j++) {
if (uniqueValues.indexOf(updatedValues[j]) === -1) {
uniqueValues.push(updatedValues[j]);
}
}
// Set the field value
g_form.setValue('versions', uniqueValues.join(','));
}
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 04:42 AM
Thanks for your response @Amitoj Wadhera
Initially we are setting the values in the field by default, as I see you provided the script even user removes the values (London & Paris) adding the values again.
Instead is it possible to make the values READ only at the beginning itself to avoid removal?
Please advise.
Thanks