| |
How to Validate Against a File or Routine, and Return an Error Message to a Web/CGI Maintenance Application |
| by Sean Crawley |
|
Let's set the scene. Let's say you've just built this great Web maintenance application that allows a user to quickly update the information surrounding a product order.
Your user wants to change the shipping date of his order. But, when he tries to change it, he accidentally enters the order's ship date as a date in the past.
Well that doesn't make any sense! And, that incorrect information will wreak havoc on reports, orders, and other system applications. So, in order to prevent incorrect data from entering those fields, you're going to want an error message to pop up to notify them that the information they've entered is incorrect.
One way to do this is to return an error message such as: "Ship Date: Please enter a date equal to or beyond today" to the user if the value entered in the ship date is less than today's date. See figure 1 below, or run this application live at http://www.crazybikes.com/employees/M00230GC.mrc.

Figure 1
And, here's how you create it:
Step 1: Write a program that does your validation & error handling. You can use the OVLDTODAY as a reference. View Source. This RPG program validates the input ship date against today's date and returns an error code to a parameter if the date entered isn't valid. We needed 2 parameters for our program, @INDATE (Ship Date Enter) and @VALID (Error Code Returned).
NOTE: The value passed to the @VALID (Error Code Returned) parameter needs to be in the range of 319-400.
Step 2: Define the program as an external object (via option 44 of mrc-Productivity Series). When defining the parameters the six characters *VALID (in all CAPS) needs to appear in the parameter description for the error code. (See Below)
| Parameter |
Description |
Size |
|
@INDATE |
In Date to Validate |
8.0 |
| @VALID |
Error Flag *VALID (Do Not Map) |
3 |
NOTE: This *VALID needs to be there to tell the mrc-generated program that it should check that particular field for an error code. If the error code is not blank, then the add/update/delete will not be performed and it will look for the text message to display from the error message .JS file.
Step 3: Create an error message .JS file and place it in the IFS of your iSeries. When defining your error codes you can use numbers in the range of 319-400, which are predefined to mrc as user defined messages. CBMSG.JS (View File) is the error message file used in our example. You'll see in the CBMSG.JS case 319: message = "Please enter a date equal to or beyond today" is retrieved to the Update Order application when an invalid date is entered. This occurs because the validation program OVLDTODAY returns '319' to the *VALID parameter if the ship date field isn't equal-to or greater-than today's date.
NOTE: mrc supplies an example .JS file, which is located in /mrcjava/mrcclasses/userdefmsg.js of the IFS. You can use the USERDEFMSG.JS as reference to create your own error message .JS files.
Step 4: Add your validation external object to the Web/CGI Maintenance application (via option 8 of the Maintenance Application options). The template location of *FLDVALID should be used to call your program. The *FLDVALID (Field Screen Validity & Error Handling) location is used for checking the value entered in a field and displaying error messages. In Update Order application, the ship date field is mapped to the @INDATE (In Date to Validate) and nothing is mapped to the @VALID Error Flag *VALID (Do Not Map) parameter. See Figure 2.
Figure 2
Step 5: Edit the HTML source to contain the location of your error message .JS file. The HTML source will have predefined USERDEFMSG.JS (which is commented out) to show where you can place your error message .JS files. So, you can place your error message file directly below the default message files. See below.
<!-- <SCRIPT LANGUAGE="JavaScript" SRC="/mrcjava/mrcclasses/userdefmsg.js" ></SCRIPT> --> <SCRIPT LANGUAGE="JavaScript" SRC="/mrcjava/mrcclasses/cbmsg.js" ></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="/mrcjava/mrcclasses/mrcjsmnt.js" ></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="/mrcjava/mrcclasses/cal.js" ></SCRIPT>
|
|
 |
mrc publishes this newsletter on a monthly basis. Subscription is free of charge. Please send any questions or comments about this newsletter to news@mrc-productivity.com. This newsletter is edited by Heather Gately.
To unsubscribe, please just reply to this e-mail with Unsubscribe in the subject line.
View our privacy promise.
|
 |
|