How to create a function with a return value - OPTION?

easy-navi
Member Posts: 31
Hello,
Is there any possibility in C/AL to create a function with a return value of a type OPTION ???
Until now - on a form I had a function called ChceckProtocolExists with a return value - boolean (True, False).
It was easy to use - on a post button of that form I wrote:
But..
Once there appeared a documents that does NOT need a protolos AND should be POSTED.
So the most logical solution is to modify a function ChceckProtocolExists to return 3 values:
Yes, No, Not applicable.
And there is a problem, because I cannot force that function to return a variable of a Option Type
Any idea ??
Is there any possibility in C/AL to create a function with a return value of a type OPTION ???
Until now - on a form I had a function called ChceckProtocolExists with a return value - boolean (True, False).
It was easy to use - on a post button of that form I wrote:
IF NOT ChceckProtocolExist() THEN ERROR('You cannot Post until there is no protocol');
But..

So the most logical solution is to modify a function ChceckProtocolExists to return 3 values:
Yes, No, Not applicable.
And there is a problem, because I cannot force that function to return a variable of a Option Type

Any idea ??
http://www.reinwestuj.pl Inwestuj w nieruchomości. Condohotele, aparthotele.
0
Answers
-
Use Integer as a return value: then you can return 0 or 1 or 2 or 3 ...No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0
-
The designer does not allow you to use Option type as a return parameter. So, you have two possibilities
- Create a procedure with no return value but a variable parameter instead, to which you assign the result
- use an Integer as the return value. Option and Integer are interchangeable (though generally not good programming style). You may use a variable of type Option within your code to make it visually more clear what the code is doing.
The consumer of your function needs to either consume it as integer anyway, or define another variable with a similarly looking option list. Since there is no Option type definition, really the only way to share an Option type is by a field in a table. Any other way is a re-declaration which easily gets out of sync on changes to the code.0 -
Thanks for your answers:). I have done it that way:Luc Van Dyck wrote:Use Integer as a return value: then you can return 0 or 1 or 2 or 3 ...
with the codeIF Int=0 THEN EXIT('No') ELSE IF Int=1 THEN EXIT('yes') ELSE IF Int=2 THEN EXIT('Not applicable')
So on the form you can make this that way:
TextBox -> SourceExpr -> TranslateCheckProtocol(ChceckProtocolExists(Rec))
(this is a textbox informing user what's happening)
And on PostButton -> OnPush Trigger ->IF ChceckProtocolExists(Rec)=0 then Error('.....');http://www.reinwestuj.pl Inwestuj w nieruchomości. Condohotele, aparthotele.0 -
Hmmm... Wondering how they managed to give function ConvertPostingType in table 5601 (in W1 2013 and W1 2013 R2) an Option return value?! Maybe it existed in the past, and the compiler accepts it, even though the designer doesn't list it?Kind regards,
Jan Hoek
Product Developer
Mprise Products B.V.0
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