Business rule not working to prevent serial number in a request form

NayeemSk
Tera Contributor

I create a business rule, which needs to prevent a serial number in a request that already exists in a table. Business Rule is not working. Attached the screenshot.

10 REPLIES 10

OlaN
Tera Sage
Tera Sage

Hi,

Some errors that needs fixing:

- As GlideFather and others already stated there's a typo, a comma instead of a dot in the if statement.

- You are missing the actual query statement 

 

Some additional performance pointers;

- You should make it a habit to always include a .setLimit(1 ) when you only need one record to optimize the query

- You could use the .hasNext() method to further enhance performance since you're not doing anything with the record found.

- I would personally use .getValue() over dotwalking, to make sure you get a string object to work with on the query

 

Final code should look something like below:

var invGr = new GlideRecord('your_table_name');
invGr.addQuery('serial_number', current.getValue('serial_number');
invGr.addQuery('sys_id', '!=', current.getUniqueValue());
invGr.setLimit(1 );
invGr.query();

if (invGr.hasNext()){
    // your logic goes here, like an error statement and the setabortaction
}