It does not matter how you stay to classic dialog forms provided by the system, but one thing is fact: Input dialogs are handy. Thank god
C/AL provides a native function to use input boxes.
NewControlID := Dialog.INPUT([ControlID][,Variable])
Luckily, someone had the brilliant idea to suspend the support for native input dialogs in
Dynamics NAV 2009 RTC and replace it by: nothing.
How would someone need such a rudimental feature that was there since the beginning of time anyway? Well, it turns out, I do. Quite a lot actually. And no: wasting
expensive pages and objects for simple input requests is not an option. Someday I came across a handy little thing which I am still using today, sitting deeply in my utilities
Codeunit. Little snippets and helper functions I am collecting to work around lacking,
unnecessary features like
IsNumeric. And there is an alternative for
INPUT as well.
What you need
Create a new function, for example
SimpleInput with the following parameters
question : Text(30) title : Text(30) defaultValue : Text(30) Return: inputResult : Text(250)
Don't make the size of the text variables too long, since you need to concat them later - and we all know what happens when we go beyond a certain length of text in Dynamics NAV...
Now you will need to add the
Windows Scripting Host COM to your local variable scope together with a temp text variable and a variable for the carriage character (CR). Now the magic begins.
Invoking the Scripting Host
An now use it
The above function seems very self-explaining. And so is the usage.
txtResult := SimpleInput( 'How do you rate this function?', 'A quick survey', '' ); MESSAGE(txtResult);
Or, let's assume you need to ask the user for a item number while he is calling an
// CUHelper is the codeunit where I store my helpers itemNo := CUHelper.SimpleInput( 'What is your favorite item no.?', 'Enter an item no.', '' ); // do some cleanup, like sanitize user input/data // ... // end of cleanup // lookup item IF recItem.GET(itemNo) THEN MESSAGE('Your favorite item is #%1 - %2', recItem."No.", recItem."Description" );
That's basically it. I hope someone finds it handy. At least I did as I found this (kind) of solution on some other blog.