Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AshikaSuresh/b964291fa6674ba4f02642d8d8cc1082 to your computer and use it in GitHub Desktop.
Save AshikaSuresh/b964291fa6674ba4f02642d8d8cc1082 to your computer and use it in GitHub Desktop.
The Allocated Budget field must be editable only by admins, while it remains read-only for all other users. When the Status is set to "Complete," the entire row should become read-only. Additionally, if the Status is anything other than "Planning," the Allocated Budget field should be restricted to read-only at the cell level. The Type of Campaign column should be visible only when the Parent Type field's value is "others." At all other times, the Type of Campaign column should remain hidden.
1. Row lock: Row setReadOnly(true) if Status = Complete
2. Cell lock: Cell setReadOnly(true) if Status != Planning
3. Field lock: Field setReadOnly(true) if Profile is other than Administrator
4. Hide/Show Subform Field : setVisibility(false) if Type == 'Others'
//Admin only can edit the Allocated budget.. for other this field will be read-only
var allocatedBudget = ZDK.Page.getSubform("Campaign_Details").getField('Allocated_Budget');
allocatedBudget.setReadOnly(true);
if ($Crm.user.profile.name != 'Administrator') {
allocatedBudget.setReadOnly(true);
}
else {
allocatedBudget.setReadOnly(false);
}
//Making `Type of Campaign` column visible when Parent `Type` field's value is 'Others'. Keeping it hidden at other times.
var type = ZDK.Page.getField('Type').getValue();
var field_obj = ZDK.Page.getSubform("Campaign_Details").getField('Type_of_Campaign');
if (type != 'Others') {
field_obj.setVisibility(false);
}
else {
ZDK.Client.showAlert('Please specify the *Type* for each Campaign');
field_obj.setVisibility(true);
}
//When Status is complete, Making entire row read only and Status is other than Planning, Keeping Allocated Budget field alone readonly [cell level readonly]
var subform_length = ZDK.Page.getSubform('Campaign_Details').getValues().length;
for (var i = 0; i < subform_length; i++){
var Status = ZDK.Page.getSubform('Campaign_Details').getRow(i).getCell('Status').getValue();
if (Status == 'Complete') {
ZDK.Page.getSubform('Campaign_Details').getRow(i).setReadOnly(true);
}
else if (Status != 'Planning') {
ZDK.Page.getSubform('Campaign_Details').getRow(i).getCell('Allocated_Budget').setReadOnly(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment