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

DarkHorse
Member Posts: 389
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.
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.
0
Answers
-
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.0 -
Thanks for your help, but how use SetRange? instead of GET?, if I put SetRange instead of GET it show's me an error.0
-
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 specialist0 -
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...0 -
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.0 -
Maybe a form1.RUNMODAL instead of form1.RUN will help.
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
Thanks for reply, but it doesn't work neither.0
-
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 specialist0 -
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.0 -
Can you post all the code that's behind the Register button?
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
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;0 -
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 specialist0 -
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.0 -
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 specialist0 -
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 specialist0 -
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.0 -
Ok.
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 specialist0 -
No, there is only one button; it's strange. Thanks for the advice about the codeunit.
Thanks again for your esteemed help.0 -
You're welcome.
Ok. Strange. :-k
Can you put (SOLVED) in the title of the first post?
Tino Ruijs
Microsoft Dynamics NAV specialist0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions