Prevent duplicate invoice vendor numbers from being entered using a custom Java class

In our forum, Dave asked if I could come up with a java class to validate whether an invoice vendor number was a duplicate.  This tutorial has a link to the custom java file that you can download and use in your own Maximo 7 instance.This tutorial isn’t about understanding MBO’s as that is a much longer blog post, but more about creating a custom java field class.  I will also show you how to add a new custom error message for when a duplicate invoice number is entered.

First, here is screen shot of what we are trying to accomplish:

Duplicate invoice vendor
Duplicate invoice vendor

As you can see, I entered invoice number 1002 and as soon as I tab out of the control or try to save the record, it shows this custom error message that I created saying that it’s a duplicate invoice vendor number.  As soon as I click OK, the ‘Vendor Invoice’ field will be cleared out.  So let’s get into how this is done.

Analyze the Java Code

First, we have to check this field if it already has a java class associated with it.  You have to go into the DB config and find the attribute ‘VENDORINVOICENUM’ and check the class field.  If there is, then we would extend that class, but since this attribute doesn’t have a java class associated with it, we will have to create our own.  Luckily, I have one right here and you can download it at the end of this post.  Here is a screen shot of the java code so you can follow what I’m talking about:

Custom Invoice Vendor Number Validation
Custom Invoice Vendor Number Validation

As you can see, it’s only a few lines of code to achieve what we want.  Let’s quickly go through some of the lines of code.

The basic idea here is that we want to take the current value in the field and query the database for invoices that have the ‘vendorinvoicenum’ equal to the current value.  We also want to check if the invoice status is equal to ‘ENTERED’, ‘WAPPR’, and ‘APPR’.  You can change these to whatever statuses you want.  If you don’t care what status it’s in then you can remove this.  But just remember, if you remove it, and you enter an invoice number that is associated with a CLOSED invoice, it will invalidate the number.

So after we execute the query, we check if the set is empty, if so, then this value is valid, otherwise we throw an exception.  This exception is the dialog box you saw in the first screen shot.  There is one to note here.  The parameters for the exception have to match the MaxMessages ID’s.  The value “InvoiceVendorExists” is a custom message key that I created for this purpose.  Before you go deploy this java class, you have to create the error message.

Creating the Custom Error Message

Go to DB configuration and go to Select Action -> Messages.  Here we want to add a new row.  For ‘Message Group’, we enter ‘invoice’.  For ‘Message Key’, we enter ‘InvoiceVendorExists’.  It is highly possible that it’s case sensitive to make sure you enter it correctly.  For ‘Message ID’, click on the magnifying class and select the first option which is ‘BMXAA’.  This will auto generate  new message ID for you.  Lastly, for the value we enter:

Invoice vendor number {0} is already associated with an open invoice.

You can enter whatever message you want to display to the user here.  Just make sure the ‘{0}’ is somewhere in the message.  This is just a place holder for the actual invoice vendor number.

Deploy the java class and configure Maximo to use the class

Once you have done this, you can go ahead and add this java class to your Maximo’s businessobjects.jar file.  To do this, you add the ‘FldInvoiceVendorNumCust.class’ file to this directory:

[maximo install folder]/applications/maximo/businessobjects/classes/interpro/app/invoice

Now you rebuild your maximo.ear file and redeploy.

Next, go into DB configuration and open the INVOICE object and find the VENDORINVOICENUM attribute.  Here we need to set the class to “”.  This will tell Maximo to use the custom validation that we created.  Save your changes and don’t forget to apply configuration changes when you are done.

Download the source files…


Did You Know...

As Maximo Experts, we have developed several add-on products for Maximo that mobilize the work force, simplifies assignments, provides ad-hoc reporting capabilities and facilitates the seamless integration of Service Requests into Maximo.

Check out our products by clicking on the following links: EZMaxMobile, EZMaxPlanner and EZMaxRequest.

Find Out More

2 thoughts on “Prevent duplicate invoice vendor numbers from being entered using a custom Java class

  1. Hi

    This is great, but does it do a search on the vendor + invoice number, as it is possible for different vendors to have the same invoice number. Also having it look at all statuses stops you trying to enter an invoice that has already been paid and closed!

    We tried to modify the class, but it does not load for us (probably operator error, we are not flash at Java!). Is there any chance in getting a modified class that combines vendor with invoice number and does not include status please??

    Hope you can help! 🙂


  2. How to change cust/vend type “Customer” if you know means please share to me

    When field 1. (Cust/Vendor) is populated then
    field 2. (Cust/Vend Type) needs to be populated with value ‘CUSTOMER’

    i.e. the logic is: IF
    Cust/Vendor field is not null THEN set Cust/Vend Type as ‘CUSTOMER’

Leave a Reply