Writing validate scripts and handling ASP pages to fire validations

By | June 5, 2012

Sage CRM provides a very essential way of writing an validate script at the Screen level in the Validate Script section to validate different types of fields in Sage CRM. This is a very basic part of development practice.
Now, if you are writing validate script in the standard Sage CRM screens, then above method works correctly. However when you write Validate Scripts on custom screens to be used in ASP pages objEntry.Validate() has to be used in order to fire validations at the time of screen execution.
As the validate script fires when saving the data, we have to write the code in the Save mode only. We also need to handle the buttons to be displayed based on mode like Save nad Cancel in Edit mode, Change, continue in view mode etc. You can refer the below code snippet which handles both buttons and validations.
 
if(eWare.Mode == Save)
{
 if(objEntry.Validate() == false)
 {
  Container.AddButton(eWare.Button(“Save”,”save.gif”,”javascript:Save();”,”Project”,”EDIT”));
  Container.AddButton(eWare.Button(“Delete”,”delete.gif”,”javascript:Delete();”,”Project”,”DELETE”));
  Container.DisplayButton(Button_Continue) = true; 
 }
 else
 {
  Container.AddButton(eWare.Button(“Change”,”edit.gif”,”javascript:Change();”,”Project”,”EDIT”));
  Container.DisplayButton(Button_Continue) = true; 
 }
}
else
{
 Container.AddButton(eWare.Button(“Change”,”edit.gif”,”javascript:Change();”,”Project”,”EDIT”));
 Container.DisplayButton(Button_Continue) = true; 
}
Here, the screen is validated in the Save mode using the objEntry.Validate() method. Now as all these entry blocks are added to container at the end, the screens are executed with no problem at all. And if the validation fails, the screen will show the validation error without navigating to the view mode.
Happy scripting!