mibuso.com

Microsoft Business Solutions online community
It is currently Mon Oct 20, 2014 6:25 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: "IF Validate" Function
PostPosted: Mon Feb 09, 2009 1:35 pm 
Offline

Joined: Mon Dec 11, 2006 10:34 am
Posts: 2883
Location: Bergamo
Country: Italy (it)
with this codeunit, you can manage the possible validate errors (like overflow etc).

Code: Select all
OBJECT Codeunit 90000 If Validate Mgt
{
  OBJECT-PROPERTIES
  {
    Date=09/02/09;
    Time=12.23.59;
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
    OnRun=BEGIN
            FNTValidate;
          END;

  }
  CODE
  {
    VAR
      INTFieldNo@1101339002 : Integer;
      TXTNewValue@1101339001 : Text[250];
      FRFieldRef@1101339004 : FieldRef;
      RRRecordRef@1101339000 : RecordRef;

    PROCEDURE FNTValidate@1101339001();
    BEGIN
      IF TXTNewValue = '' THEN BEGIN
        FRFieldRef.VALIDATE;
      END ELSE BEGIN
        EVALUATE(FRFieldRef,TXTNewValue);
        FRFieldRef.VALIDATE;
      END;
    END;

    PROCEDURE FNTGetPar@1101339003(INTLocTableNo@1101339000 : Integer;INTLocFieldNo@1101339001 : Integer;TXTLocPosition@1101339002 : Text[1000];TXTLocValue@1101339003 : Text[250]);
    BEGIN
      TXTNewValue := TXTLocValue;
      RRRecordRef.OPEN(INTLocTableNo);
      RRRecordRef.SETPOSITION(TXTLocPosition);
      RRRecordRef.FIND('=');
      FRFieldRef := RRRecordRef.FIELD(INTLocFieldNo);
    END;

    PROCEDURE FNTGetTableNo@1101339000(TXTTableName@1101339001 : Text[50]) : Integer;
    VAR
      TBObject@1101339000 : Record 2000000001;
    BEGIN
      TBObject.SETRANGE(Type,TBObject.Type::Table);
      TBObject.SETRANGE(Name,TXTTableName);
      TBObject.FINDFIRST;
      EXIT(TBObject.ID);
    END;

    BEGIN
    END.
  }
}


Here's an example on how to use this codeunit:

Code: Select all
OBJECT Codeunit 66666 getpos
{
  OBJECT-PROPERTIES
  {
    Date=09/02/09;
    Time=12.27.22;
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
    OnRun=BEGIN
            txtconst := 'mlallalllllflljfdshalfjadskfljadslfkjadslfjhadslfjhadsfhsadlkfhdslafhekhfuniciabernciebhrigvbiero';
            tbtest.FINDLAST;
            cu.FNTGetPar(cu.FNTGetTableNo(tbtest.TABLENAME),tbtest.FIELDNO(Name),tbtest.GETPOSITION(FALSE),txtconst);
            IF cu.RUN THEN BEGIN
              tbtest.VALIDATE(Name,txtconst);
              tbtest.MODIFY;
            END ELSE BEGIN
              MESSAGE('What customer is this?');
            END;
          END;

  }
  CODE
  {
    VAR
      tbtest@1101339000 : Record 18;
      rref@1101339001 : RecordRef;
      cu@1101339002 : Codeunit 90000;
      txtconst@1101339003 : Text[200];

    BEGIN
    END.
  }
}

Maybe there are problems with transactions, codeunit.run and "complex" validates...not tried yet...for sure, you should know what you are validating before using this function. :mrgreen:

*edit:
a possible use of this codeuint is when you are batch processing something: you can use getlasterrortext function to create a simple log if the validate goes error...
Enjoy!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Exabot [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: