Skip to content

Instantly share code, notes, and snippets.

@furkankaracan
Created March 26, 2024 21:37
Show Gist options
  • Save furkankaracan/2a88775525b10a015b4732883632de13 to your computer and use it in GitHub Desktop.
Save furkankaracan/2a88775525b10a015b4732883632de13 to your computer and use it in GitHub Desktop.
function OnLoad(executionContext){
var formContext = executionContext.getFormContext();
//Register custom event
formContext.data.entity.addOnSave(validateOpportunityScore);
}
function validateOpportunityScoreOnSave(executionContext) {
var formContext = executionContext.getFormContext();
var opportunityScore = formContext.getAttribute("new_opportunityscore").getValue();
if (opportunityScore < 0 || opportunityScore > 100) {
formContext.getControl("new_opportunityscore").setNotification("Opportunity score must be between 0 and 100.");
//Prevent save
executionContext.getEventArgs().preventDefault();
} else {
formContext.getControl("new_opportunityscore").clearNotification();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment