How to validate quantity from another field ?

haihthhaihth Member Posts: 32
Hi all,

I'm trying to insert a new line into sales line with code below
No. - OnAfterValidate()
SL.RESET;
SL."Line No.":=GetLastLineNo(Rec."Document No.")+10000;
SL."Document Type":="Document Type";
SL."Document No.":=Rec."Document No.";
SL.Type:=Rec.Type;
SL."No.":='AAA';
SL.VALIDATE("No.");                
SL.Quantity:=1000;
SL.VALIDATE(Quantity);
SL.INSERT;
CurrForm.UPDATE;

Everything is OK except the quantity of item AAA is not checked with inventory.
When i input quantity of AAA by manual, the system warning "Check Availability". But when i using code like above, the system not check inventory of item AAA.

How can I call validate quantity from another field.

Thanks for helping me.

Comments

  • lvanvugtlvanvugt Member Posts: 774
    Have you run the code using the debugger to see if it did execute (and how) the CheckItemAvailable function?
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • DenSterDenSter Member Posts: 8,305
    <snip>
    SL."No.":='AAA';
    SL.VALIDATE("No.");                
    SL.Quantity:=1000;
    SL.VALIDATE(Quantity);
    
    OK so in general, just a few things:
    1 - DO NOT give your variables these weird names. If you have a record variable into the Sales Line table, then call it SalesLine. It makes the code easier to read, less effort to troubleshoot, and all around better for everyone.

    2 - you can directly assign a value while using VALIDATE, like this:
    SalesLine.VALIDATE("No.",'AAA');                
    SalesLine.VALIDATE(Quantity,1000);
    
  • haihthhaihth Member Posts: 32
    lvanvugt wrote:
    Have you run the code using the debugger to see if it did execute (and how) the CheckItemAvailable function?

    I've checked the funtion CheckItemAvaible in Sales Line table. It'll run with current field no. But i can not call this function from form trigger "No." OnAfterValidate.

    When I call

    SL.CheckItemAvailable(FIELDNO("No."));

    The system warning . ( SL is record Sales Line )

    "You have specified an unknown variable. CheckItemAvailable"

    How can i call this function from trigger OnAfterValidate of "No." field
  • SavatageSavatage Member Posts: 7,142
    You're doing this from form level, not table?
  • haihthhaihth Member Posts: 32
    Savatage wrote:
    You're doing this from form level, not table?

    Yes. I want to call this function from form level because i just have permission on form. Not table.
Sign In or Register to comment.