Skip to main content
Version: 8.1

Reset negative values to 0 in the mobile app

Level: advanced
Example

Implement the logic for dropping negative values to 0.

Example implementation

Reset negative values to 0
Terrasoft.sdk.Model.addBusinessRule("Opportunity", {
name: "OpportunityAmountValidatorRule",
ruleType: Terrasoft.RuleTypes.Custom,
triggeredByColumns: ["Amount"],
events: [Terrasoft.BusinessRuleEvents.ValueChanged, Terrasoft.BusinessRuleEvents.Save],
executeFn: function(model, rule, column, customData, callbackConfig) {
var revenue = model.get("Amount");
if ((revenue < 0) || Ext.isEmpty(revenue)) {
model.set("Amount", 0, true);
}
Ext.callback(callbackConfig.success, callbackConfig.scope);
}
});