Problem with a code

Leroy
Leroy Member Posts: 199
Dear folks, I've the following code on OnValidate trigger from "Qty. to Receive" field from "Purchase Line" table:
 IF ("Qty. to Receive"<>0)
   THEN MESSAGE:='text';

I want simply that shows a message when the quantity that you put on this field manually should be more than 0, but it occurs something strange; it shows me the message when I put a quantity on Quantity field, not in 2Qty. to Receive" (it is on 0). Does anybody knows what's the problem?.
Thanks in advance.

Comments

  • kriki
    kriki Member, Moderator Posts: 9,127
    Quantity-OnValidate does a VALIDATE of "Qty. to Receive".
    You should change your code to
    IF CurrFieldNo = FIELDID("Qty. to Receive") THEN
      IF ("Qty. to Receive"<>0) THEN 
        MESSAGE:='text';
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Leroy
    Leroy Member Posts: 199
    Thanks for repy, but, what have I to put in FIELDID, please?.
  • kine
    kine Member Posts: 12,562
    FIELDID is method of the Rec. variable returning ID of the field entered as parameter, you do not need to enter anything... :wink:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Leroy
    Leroy Member Posts: 199
    Thanks, but the problem is that doesn't run, it shows an error on FIELDID on saving; what's the problem please?.
    Thanks for help in advance.
  • kriki
    kriki Member, Moderator Posts: 9,127
    My error :oops:
    FIELDID must be FIELDNO
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kine
    kine Member Posts: 12,562
    kriki wrote:
    My error :oops:
    FIELDID must be FIELDNO

    I didn't notice that too... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Leroy
    Leroy Member Posts: 199
    Thanks for reply, no problem; but now it doesn't show me any message when I put something in "Qty. to Receive" field. Any idea please?.
    Thanks in advance.
  • kine
    kine Member Posts: 12,562
    May be you need to use
    Message(TextConstant);
    

    and not assigning some text to some variable... ;-)

    We assumed that the message is some variable which is used in some way after the text is assigned...

    But it depends on rest of the code...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Leroy
    Leroy Member Posts: 199
    Thanks for reply; the whole code (on the beggining from "Qty. to Receive" OnValidate trigger) is this:
    IF CurrFieldNo = FIELDNO("Qty. to Receive") THEN
      IF ("Qty. to Receive"<>0)
    THEN BEGIN
    MESSAGE:='You must charge 2€ to the unit cost';
    END;
    

    I don't use a variable for the message. Any idea about it please?.
    Thanks for help.
  • Leroy
    Leroy Member Posts: 199
    Sorry :oops: , I see what's my problem. I add another condition. I mean. The real code is
    IF CurrFieldNo = FIELDNO("Qty. to Receive") THEN
      IF ("Qty. to Receive"<>0)
    AND  (Item.Tooling=TRUE)
    THEN BEGIN
    MESSAGE:='You must charge 2€ to the unit cost';
    END;
    

    I add the condition "AND (Item.Tooling=TRUE)". If I don't put it It works perfectly, but if I put it doesn't do anything. How can I put this new condition?.
    Thanks for your help.
  • kine
    kine Member Posts: 12,562
    1) When using boolean variable in condition, you do not need to use =true or =false.
     IF ("Qty. to Receive"<>0) AND  Item.Tooling THEN   //or  AND (not Item.Tooling)  if you need to test for FALSE
    
    2) Never use hardcoded text constants when the text will be used in GUI (shown to user). Use the text constant to be able to use different translations (be prepared for multilanguage). It means define the text constant with the text and instead the string assign the text constant in the code.
    3) If you want to test something on the Item variable, you need to get some record into it first. it means you need to use e.g. Item.GET("No.") before using the Item... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Leroy
    Leroy Member Posts: 199
    Ooops :oops: ,shit..., as you say on point 3 I needed initialize the Item table; I had it initialized in a trigger before, but it seems like don't keep it. It works perfectly now =D> .
    Thank you very much for help and your time.
  • Zephyr
    Zephyr Member Posts: 110
    When you compare some record then you have to keep and 2 way to keep then

    1.) First you can be use GET method for if you know primary key (first field).
    2.) Second you can use FILTER of that table and then apply FINDFIRST.
    Zephyr