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:
IF NOT ChceckProtocolExist() THEN
ERROR('You cannot Post until there is no protocol');
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 ??
http://www.reinwestuj.pl Inwestuj w nieruchomości. Condohotele, aparthotele.
Answers
- 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.
I'd strongly prefer the latter.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.
with the code
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 -> \:D/
Jan Hoek
Product Developer
Mprise Products B.V.