Validate Data - Adding Addl Validation Outside of BE Designer
 
Forums / SmartComponent Library - Developer Forum / Validate Data - Adding Addl Validation Outside of BE Designer

Validate Data - Adding Addl Validation Outside of BE Designer

3 posts, 1 answered
  1. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    21 Dec 2018
    Link to this post
    I have added Validation to a field using the Business Entity Designer. When the BE is created it has the following code in VaidateData.

    @GeneratedValidationStart.
            /* The following code is auto-generated. Don't insert custom code
               between the @GeneratedValidationStart. and @GeneratedValidationEnd.
               annotations as it would get overwritten when you update the Business
               entity. */
            FOR EACH eItem WHERE ROW-STATE (eItem) <> ROW-UNMODIFIED ON ERROR UNDO, THROW:
                Consultingwerk.OERA.ValidationHelper:IsInRange (BUFFER eItem:HANDLE, "DeptNum":U, 1, 99, "A DeptNum must be between 1 and 99":U).
            END .
    @GeneratedValidationEnd.

    If I needed to add addl validation where would I put it? In another FOR EACH eItem loop or just do not do this in the BE Designer? I need to make sure the selected codes for certain field have an associated record in another table. For example, I need to perform a CAN-FIND on the chosen Deptnum.  
           
    VALIDATE:CanFind(BUFFER eItem:HANDLE,
                                "DeptNum",
                                "Osprey.Pos.Dept.DeptBusinessEntity",
                                "eDept",
                                SUBSTITUTE ("FOR EACH eDept WHERE eDept.DeptNum = &1":U, eItem.DeptNum),
                                 MessageFormatter:GetMessage("VALMSG":U, 2, "DeptNum")).
  2. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    Answered
    21 Dec 2018 in reply to Roger Blanchard
    Link to this post
    Custom validation code should be coded in another FOR EACH block. 

    The FOR EACH between the @GeneratedValidationStart. and @GeneratedValidationEnd. block will be overwritten by the Business Entity Generator everytime you re-generate a Business Entity. 

    Two FOR EACH loops on typically a very small number of modified temp-table records iss not really performance relevant. 
  3. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    21 Dec 2018 in reply to Mike Fechner
    Link to this post
    Thanks for the response. That is what I did...just wanted to confirm.
3 posts, 1 answered