Monday, April 6, 2015

Create Yes/No Message Box in X++

During your form or report development you might require response Yes/No from user in order to start any action. In this topic, i will show you on how to create a Yes/No message box to get user response in X++.
In your void main() function you need to write code as below:

1. DialogButton diagBut;
2. str strMessage = "Do you want to print Debit or Credit Note? Click Yes for Debit Note., No for Credit Note.";
3. str strTitle = "Report Selection";
4. ;
5. diagBut = Box::yesNo(strMessage, DialogButton::Yes, strTitle);
6. if(diagBut == DialogButton::No)
7. {
8. //your own code when user click on No button

9. }
10. if(diagBut == DialogButton::Yes)
11. {
12.
//your own code when user click on Yes button
13. }

Now, I will explain above code line by line for you to understand easily.
Line 1: To declare a variable with type DialogButton 
Line 2: To declare a string variable for message body
Line 3: To declare a string variable for message title
Line 4: This is just a best practice recommended by Microsoft to separate variable declaration.
Line 5: This is a combination of message body, message title and assign message button
Line 6: This is a condition study in case user response by click on No button
Line 7: Opening of If block
Line 8: In this block you need to add any code that you want system to do
Line 9: Ending of If block
Line 10: This is a condition study in case user response by click on Yes button
Line 11: Opening of If block
Line 12: In this block you need to add any code that you want system to do
Line 13: Ending of If block

1 comment: