Informing the IBM Community

A NodeJS Website on IBM i – Updating Records

0
(0)



Continuing with my Node.js Express website on IBM i theme, in this article I’ll show you how easy it is to update employee records from our database.

Building on the previous article, on how to delete records, we will use the same structure to update, by using a popup window to allow the user to amend records.

The stages we need to go through to develop this functionality is as follows:

  1. Allow user to select an employee to update
  2. Show a popup window with the current employee details
  3. Ask the user to input new details
  4. If the user confirms the update, then update the record
  5. Send a status message back to the user, letting them know if the update was successful, or not
  6. Refresh the browser window, showing the current list of employees.

In pictorial form, it will look like this.

The user will select an employee to update.

A popup window will ask the user to input any new details of the selected employee.

A status message will show the user the results of the update request.

So, how do we achieve all this?

Coding

The first step we have to do, is to modify our employee.pug file to show an update icon in the employee table.

We add another column, with the font-awesome icon for update.

We have to make this an HTML link. This can be seen in the coding below.

Popup Window

Also, within the employee.pug file we have to code the popup update window. 

This is very similar to the delete popup window we coded in my last article.

The next part of the coding is to add the JavaScript functions to display the popup window. 

This is added to the end of the employee.pug file.

Next, we need to add the delete JavaScript function (submitDeleteForm), this is also coded within the employee.pug file.

AJAX Script

Once we have all the above in place, we need the AJAX script that is going to perform the employee update. 

In the last article, I called this script ajax_employee.js  We will add the update function to this script to keep all our database access within one script.  This makes life easier for maintenance.

Testing

Let me show you what happens when the SQL delete fails, for whatever reason.

The popup window, after the AJAX call, will display a standard error message.

No great clues there as to what went wrong, but if we look at the console log, we see the SQL error messages that are returned from our server.

Ah a typo, should be EMPLOYEE not EMPLOYEEX.  Not the first time my typing has let me down!

GitHub

As with all my previous articles on this topic, these changes have now been published to my GitHub repository, which can be found at this link.  Hopefully, this will provide you with a template to experiment with Node.js on IBM i.

Conclusion

Hopefully in this article I’ve shown how easy it is to select an employee record, display a confirmation pop-up window and then update that employee record.

Now we have all the main functionality in our employee website, in the next article, we will piece all the bits together to make a fully functional application for our employees.

If you have any questions, either on this article, or any other open source, use the comments below, or send me a message on twitter @AndyYouens

Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 40 years IBM midrange experience.



How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *