Business rule not working to prevent serial number in a request form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
}