Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AshikaSuresh/e2e0a8fb7f48ec5655dfd46be426f078 to your computer and use it in GitHub Desktop.

Select an option

Save AshikaSuresh/e2e0a8fb7f48ec5655dfd46be426f078 to your computer and use it in GitHub Desktop.
If the Allocated Budget of all campaigns exceeds the Total Budget Allocated, prevent the row from being saved and display an error message.
Prevent row save on criteria mismatch: Use beforeRowUpdate subform event to return false and display an error with showError().
var total_budget = ZDK.Page.getField('Total_Budget_Allocated').getValue();
log("Total Budget :" +total_budget)
var subform_length = ZDK.Page.getSubform('Campaign_Details').getValues().length;
var total = 0;
for (var i = 0; i < subform_length; i++){
var allocatedBudget = ZDK.Page.getSubform('Campaign_Details').getRow(i).getCell('Allocated_Budget').getValue();
var audience = ZDK.Page.getSubform('Campaign_Details').getRow(i).getCell('Expected_Audience_count'); audience.getValue();
log('Allocated budget : ' + allocatedBudget)
log('audience count : '+audience)
total = total + allocatedBudget;
}
log('Total : ' + total);
if (total >= total_budget) {
ZDK.Page.getSubform('Campaign_Details').getRow(index).getCell('Allocated_Budget').showError('Budget exceeds the total budget allocated');
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment