How to evaluate GETFILTER when using option fields??

Mike_HWG
Member Posts: 104
I want to do something like this:
Let's say I set a filter of Order and run the code. The above doesn't ever evaluate to true because GETFILTER returns 'Order' and the FORMAT returns '1'.
How do I do a correct evaluation? ](*,)
CASE SalesLine.GETFILTER("Document Type") OF FORMAT(SalesLine."Document Type"::Order): // Do stuff END;
Let's say I set a filter of Order and run the code. The above doesn't ever evaluate to true because GETFILTER returns 'Order' and the FORMAT returns '1'.
How do I do a correct evaluation? ](*,)
Michael Hollinger
Systems Analyst
NAV 2009 R2 (6.00.34463)
Systems Analyst
NAV 2009 R2 (6.00.34463)
0
Answers
-
Weird how that happens isn't it, but this is one case where you'll have to hard code it.0
-
I was wondering if it was going to come to that, I just felt wrong for thinking about it :PMichael Hollinger
Systems Analyst
NAV 2009 R2 (6.00.34463)0 -
Yeah it does feel all wrong, and it is, but when you don't have a choice....0
-
Mike_HWG wrote:I want to do something like this:
CASE SalesLine.GETFILTER("Document Type") OF FORMAT(SalesLine."Document Type"::Order): // Do stuff END;
Let's say I set a filter of Order and run the code. The above doesn't ever evaluate to true because GETFILTER returns 'Order' and the FORMAT returns '1'.
How do I do a correct evaluation? ](*,)
try thissalesheader.reset; salesheader.copyfilters(rec); for i := 0 to 5 do begin salesheader2."Document Type" := i; if salesheader.getfilter("document type") = strsubstno('%1',salesheader2."Document Type") then CASE salesheader2."Document Type" OF salesheader."Document Type"::quo : message('You filtered on quote'); salesheader."Document Type"::order : message('You filtered on Order'); salesheader."Document Type"::invoice : message('You filtered on invoice'); salesheader."Document Type"::cre : message('You filtered on Credit Memo'); END; end;
David Singleton0 -
Or of couse, you can use the third parameter of the FORMATfunction to return string representation instead number... ;-)1
-
kine wrote:Or of couse, you can use the third parameter of the FORMATfunction to return string representation instead number... ;-)
Even better. :thumbsup:David Singleton0 -
kine wrote:Or of couse, you can use the third parameter of the FORMATfunction to return string representation instead number... ;-)
MESSAGE(FORMAT(SalesHeader."Document Type"::order,0,'<Text,0>')); MESSAGE(FORMAT(SalesHeader."Document Type"::order,0,'<Text,1>')); MESSAGE(FORMAT(SalesHeader."Document Type"::order,0,0)); MESSAGE(FORMAT(SalesHeader."Document Type"::order,0,1)); MESSAGE(FORMAT(SalesHeader."Document Type"::order,0,'<Standard Format,1>'));
They all show the number:
Microsoft Dynamics NAV Classic
1
OK
None of them show the text representation of the option field. By this time I would have lost patience and just hardcoded the value0 -
Ah, I understand, the problem is, that you are formating the constant, whcih is INTEGER in result, thus still getting the number. If you use variable of type option and you will set the value into it and format it, you will get the option text.0
-
DenSter wrote:
None of them show the text representation of the option field. By this time I would have lost patience and just hardcoded the value
Mine worksDavid Singleton0 -
David Singleton wrote:Mine works
salesheader.reset; salesheader.copyfilters(rec); if salesheader.findset then if salesheader.getfilter("document type") <> '' then message('You filtered on document type %1',format(salesheader."document type")) ;
Note to self.. Pressing F11 in a browser doesn't compile0 -
MBerger wrote:David Singleton wrote:Mine works
But that is an entirely different issue CASE can't ever work like a filter. No matter what you would need to break up the comma string. I think you are confusing two different problems into one. I have shown you how to solve the question you asked, now you need to address the next one. I can see plenty of ways to solve it. For a small number of options like yours I would create an Array or options, for a larger selection I would use a temporary table.David Singleton0 -
As a hint you are going to need something like:
salesheader.reset; salesheader.copyfilters(rec); for i := 0 to 5 do begin salesheader2."Document Type" := i; OptionFound[i] := STRPOS(strsubstno('%1',salesheader2."Document Type"),salesheader.getfilter("document type")) <> 0 ....
David Singleton0 -
David, I think there's a point where the complexity is going to outweigh hard-coding... at least at this point with the tools we have. Thinking about switches like <>, .., &, *, and so on, you will eventually get yourself into building a parser. I guess you could create a really good set of functions built for this and add it to your 'tool bag' codeunit... let me know when I can download itkine wrote:Ah, I understand, the problem is, that you are formatting the constant, which is INTEGER in result, thus still getting the number. If you use variable of type option and you will set the value into it and format it, you will get the option text.
Umm... I don't think I'm getting it, because this gives me '1' as well:MyOption := Salesheader."Document Type"::Order; MESSAGE(FORMAT(myoption)); MESSAGE('%1',MyOption);
Michael Hollinger
Systems Analyst
NAV 2009 R2 (6.00.34463)0 -
Mike_HWG wrote:David, I think there's a point where the complexity is going to outweigh hard-coding...
I see now that the post I replied to before was not yours. I think Mberger has just taken the whole thread down a completely different direction and added confusion.
To MBerger, a CASE command can NOT handle multiple valid options, it gets to the first one then exits.
Mike if all you want is what you asked in your original post then my code does exactly what you want.David Singleton0
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