"Code expression can’t turn to a Option value”

DarkHorseDarkHorse Member Posts: 389
edited 2008-04-10 in Navision Attain
Dear folks, I want that, when a purchase invoice is registered and the VAT Prod. Posting Group field, from Purchaser line table, is VAT16, automatically it goes to a form that I’ve created.
I put the following code in the OnPush form the register button:

purchaseline.INIT;
IF purchaseline.GET("Buy-from Vendor No.") THEN;
IF purchaseline."VAT Prod. Posting Group"='VAT16' THEN
form1.RUN;

(The purchaseline var is the Purchase Line table, and the form1 var is the form that I want to show when VAT Prod. Posting Group field is VAT16)

But, when I register the invoice it shows me the message “The Code expression can’t turn to a Option value”.
Please, anybody knows how I can solve it?.
Many thanks in advance.

Answers

  • McClaneMcClane Member Posts: 40
    The error is caused by get command. Primary Key of the Table "Purchase Line" is "Document Type, Document No., Line No.", where "Document Type" is an Option-Field, so that the expression "purchaseline.GET("Buy-from Vendor No.")" wont ever work.

    if you want to search for the Vendor No, you will have to use SetRange.
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for your help, but how use SetRange? instead of GET?, if I put SetRange instead of GET it show's me an error.
  • tinoruijstinoruijs Member Posts: 1,226
    purchaseline.RESET; 
    purchaseline.SETRANGE("Document Type", "Document Type");
    purchaseline.SETRANGE("Document No.", "No.");
    purchaseline.SETRANGE("Buy-from Vendor No.", "Buy-from Vendor No.");
    if purchaseline.FINDFIRST THEN BEGIN;
      IF purchaseline."VAT Prod. Posting Group"='VAT16' THEN 
        form1.RUN; 
    END;
    

    But this only works if the first purchase line is VAT16.

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • kinekine Member Posts: 12,562
    tinoruijs wrote:
    purchaseline.RESET; 
    purchaseline.SETRANGE("Document Type", "Document Type");
    purchaseline.SETRANGE("Document No.", "No.");
    purchaseline.SETRANGE("Buy-from Vendor No.", "Buy-from Vendor No.");
    if purchaseline.FINDFIRST THEN BEGIN;
      IF purchaseline."VAT Prod. Posting Group"='VAT16' THEN 
        form1.RUN; 
    END;
    

    But this only works if the first purchase line is VAT16.

    1) Because we are in the Attain forum, I assume that DarkHorse is using NAV 3.60 or 3.70 and it means that he can use just FIND('-') instead FINDFIRST
    2) DarkHorse: never use the "magic constant" like you are using the "VAT16". Add new field into some setup table, where user can select this value, and use this field from the setup to compare it with the value from PurchaseLine...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DarkHorseDarkHorse Member Posts: 389
    Thanks everybody for help. I'ill try it exactly (only changing FINDFIRST by Find('-')) and it doesn't shows me the message, but when I register the invoice it doesn't go to the form1, it simply go to the same window. Does anybody knows what's the problem?.
    Thanks in advance.
  • tinoruijstinoruijs Member Posts: 1,226
    Maybe a form1.RUNMODAL instead of form1.RUN will help.

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply, but it doesn't work neither.
  • tinoruijstinoruijs Member Posts: 1,226
    Is "VAT Prod. Posting Group" on the first purchase line 'VAT16'?
    Only the first purchase line is checked.
    Maybe you want to run the form when one of the purchase lines has purchaseline."VAT Prod. Posting Group"='VAT16'?

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • DarkHorseDarkHorse Member Posts: 389
    Yes, I know, to prove it I only do one line on purchase line with VAT16 on Vat prod posting group.
    It's curious because it seems that it look for because the process take a long time and, on the state line, you can see as it look for on the purchase line table, but finally it doesn't go to the form.
  • tinoruijstinoruijs Member Posts: 1,226
    Can you post all the code that's behind the Register button?

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • DarkHorseDarkHorse Member Posts: 389
    Of course, thanks for help.


    purchaseline.RESET;
    purchaseline.SETRANGE("Document Type", "Document Type");
    purchaseline.SETRANGE("Document No.", "No.");
    purchaseline.SETRANGE("Buy-from Vendor No.", "Buy-from Vendor No.");
    IF purchaseline.FIND('-') THEN BEGIN;
    IF purchaseline."VAT Prod. Posting Group"='VAT16' THEN
    form1.RUN;
    END;
  • tinoruijstinoruijs Member Posts: 1,226
    You could use debugger to see what goes wrong.

    Or you could replace form1.RUN; by MESSAGE('TEST'); and see if you get the message.

    By the way. When modifying a form you should close NAV and login again to make sure you test the correct form.
    Or at least close the form you just modified. And put the Object Cache (KB) to 0 (Tools, options, Object Cache (KB)).

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply. I've put a message and it shows on the following position:


    lineacompra.RESET;
    lineacompra.SETRANGE("Document Type", "Document Type");
    lineacompra.SETRANGE("Document No.", "No.");
    lineacompra.SETRANGE("Buy-from Vendor No.", "Buy-from Vendor No.");
    MESSAGE:='HELLO';
    IF lineacompra.FIND('-') THEN BEGIN;
    IF lineacompra."VAT Prod. Posting Group"='VAT16' THEN
    formulario1.RUN;
    END;

    After that line the message doesn't show, it means that the rest of the lines doesn't work.
  • tinoruijstinoruijs Member Posts: 1,226
    Maybe there are two buttons Register on your form. Modify the form and move to button a bit. Could be there's a button beneath it..

    If so, you have to put the code in two OnPush-triggers. Better is then to create a function and call the function from both the OnPush-triggers.

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • tinoruijstinoruijs Member Posts: 1,226
    Maybe there are two buttons Register on your form. Modify the form and move to button a bit. Could be there's a button beneath it..

    If so, you have to put the code in two OnPush-triggers. Better is then to create a function and call the function from both the OnPush-triggers.

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • DarkHorseDarkHorse Member Posts: 389
    I don't know the reason but, instead of put the code on the push button, I've put it on de 91 Codeunit that do the register process of the invoice and It works!!! =D> from there, I don't know the reason, the code it's the same.
    The form shows me during the register process and I want to show it at the final of it, it's not very important, I think it's just a few testings.
    Thank you very much for help and your time.
  • tinoruijstinoruijs Member Posts: 1,226
    Ok. :D
    If it works, it's fine!
    Look out with modifying posting codeunits. The code you used now can't do much wrong, but be careful.

    Have you checked if there were 2 buttons?

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • DarkHorseDarkHorse Member Posts: 389
    No, there is only one button; it's strange. Thanks for the advice about the codeunit.
    Thanks again for your esteemed help.
  • tinoruijstinoruijs Member Posts: 1,226
    You're welcome.

    Ok. Strange. :-k

    Can you put (SOLVED) in the title of the first post?

    Tino Ruijs
    Microsoft Dynamics NAV specialist
Sign In or Register to comment.