Server Side Validation and ASP pages

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Server Side Validation and ASP pages

  • Comments 6
  • Likes
If you need to perform some server side validation within an ASP page that would use the standard CRM behaviour to highlight the field that contains the invalid data. Then the simplest approach is to use Validation Rules.

These can be defined either at the level of the screen or applied to a screen within the code of the ASP page.

The basic structure of a Validation rules looks like this:

//////////

if (Values("field_name")!=strExpectedValue)
{
Valid = false;
ErrorStr = "Error Message Goes Here"
}

//////

Valid when set to false will return the screen to edit mode and will indicate the offending field to the user. The field is marked with a a red star and the contents of the ErrorStr is written out.

The Values("field_name") collection allows you to access the submitted fields.

If you define the Validation rule in meta data (in the screen defination) e.g. in the companyboxlong screen then wherever this screen is used then the rule will be applied.

If you only want to add a rule to a screen in an ASP page this can be done using the field properties.

E.g.

var myEntryBlock = myBlock.GetEntry("field_name"); //myBlock is the screen
with (myEntryBlock)
{
ValidateScript = "if (Values('field_name')<=20){Valid=false;ErrorStr='Error';}";
}
Comments
  • above script is not working

  • Which script?  The ASP example or the serverside example?

  • Hi Jeff

    Is there a way to write an error message on a list page if certain conditions are not true?

    ErrorStr does not work here.

  • Nic - what sort of condition do you mean?  Can you provide a business rule example?

  • Hi Jeff

    I am trying to implement some validation on an asp page I created using a post you made in 2011.

    community.sagecrm.com/.../adding-dedupe-behaviour-to-the-lead-entity.aspx

    (very impressed with this)

    The dedupe behaviour works perfectly however I am unable to validate any of the fields on the Newleadsearch.asp

    What I would like to do is validate the second field (comp_postcode)so that it must contain at least 2 characters.

    I have tried the asp validation code in the above post however I am struggling to get it to work. I added the above script directly after the "LeadBlock.FormAction = eWare.URL("newleadsearchresult.asp");" section but the resulted in a 500 error.

    Do you have any ideas on where I am going wrong and what I can do to attain this validation?

    I am using this on a Sage 200 CRM 7.1g.

    <!-- #include file ="accpaccrm.js"-->

    Cheers

    Rob

  • Rob

    Have a look back at the article that describes the Lead Dedupe behaviour  community.sagecrm.com/.../adding-dedupe-behaviour-to-the-lead-entity.aspx

    You will see a comment from Stacy Denunzio that describes how he added additional validation to the page.