RAMP TS007 Step 3 Add Error Handling

RAMP-TS

RAMP-TS007 Step 3. Add Error Handling

In this step you will add code to your script to issue a message if the new employee insertion was successful.

After any attempted insert (whether successful or not), the NewEmployee screen is redisplayed. Therefore you can place the error handling code in the ARRIVE script of the screen. You will then add code to close the New Employee window if a new employee has successfully been added.

 

For the error handling you will need a Javascript function to trim the employee number.

1.   Add this function code to the end of your script,  just before the SYSINFO:

   /* ====================================================== */
   /* ===================  uTrim  ========================== */
   /* ====================================================== */
   /* sStringToTrim: The string to be trimmed left and right */


   uTrim : function (sStringToTrim) {

   return sStringToTrim.replace(/^\s+|\s+$/g,"");

   } ,

 

Your code will look like this:

 

You will only want to execute the error handling code when the NewEmployee screen is redisplayed, so you will first need to check what the previous screen was:

2.   Add this statement after the declaration of the bReturn variable in the vHandle_ARRIVE function:

    if (oPreviousForm.vName == "NewEmployee" )
     {
     }

 

To differentiate between a successful insert and a validation error add code to check whether the employee number has been set to blank by the operation. If it is not blank, close the window:

3.   Add this code to the if statement:

         /* Get the currently showing EMPNO */
         var strCurrEmpno = GETVALUE("txtEmpno");
         if ((this.uTrim(strCurrEmpno) == "") && (this.uTrim(oPayload.empno) != "") )
         {
            /* Insert was sucessful */
            /* Issue a message  */
            MESSAGE("Employee ", oPayload.empno ," created");
            AVCLOSEFORM();
         }

Your code will look like this:

 

4.   Click on Commit Changes and then do a partial save.

5.   In the Framework add a new employee. Notice that after you have successfully added an employee, the message is displayed and the window is closed.