- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 05:13 AM
Hi all,
I have the following issue. I have a custom table and a business rule set on it that avoids creating a record when a particular condition is met.
The business rule is set to rune BEFORE and in the script I have the usual command:
I've added some logs to check if the business rules and the setAbortAction were running and they are.
The behavior I get is the following:
1. If in a script a create the record, I get the error message but a new ID is still created, even if the record is not added to the table:
2. If I create a record using a Script API it returns 201 (cause the record ID is created) but the record is not actually in the table. How do I get the result of the business rule in the script? Or is there a way not to generate the record ID so I can check in the Create API if the record was actually created?
Would you know how to sort out this issue?
Thanks,
Alex
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 10:15 AM
@Alessandro Penn Whenever a new record is about to be created a function getNextObjNumberPadded is called and a number is assigned to the new record before its creation. Since the record is aborted before when the order id was empty, it wasn't stored with in the table. However, the Number counter incremented and hence the next records get a number greater than the previous number.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 05:21 AM
@Alessandro Penn Based on the screenshot, I am assuming that the record should not get created if the order field is empty on the record. However, the condition on the business rule seems to be incorrect which check Order is not empty. Ideally, it should check Order is empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 08:38 AM
Hi @Sandeep Rajput ,
apologies, I must have changed the value by mistake when I was taking the screenshot.
The actual business rule states: Order is empty.
Now, the business rules gets triggered correctly, the behavior I found is that, a new ID is created but then the record is not created.
So, for example, if you run first this script:
var customTable = 'x_custom_table';
var customGR = new GlideRecordSecure(customTable );
customGR .initialize();
customGR.order= "";
customGR.insert();
gs.addInfoMessage(customGR.number);
You get the following output:
Background message, type:info, message: VEN0001809
If you the run the following script:
var customTable = 'x_custom_table';
var customGR = new GlideRecordSecure(customTable );
customGR .initialize();
customGR.order= "12345";
customGR.insert();
gs.addInfoMessage(customGR.number);
You get the following output:
Background message, type:info, message:
If you now check in the custom_table, there's no record having ID VEN0001809, but there is a record having ID: VEN0001810.
I hope this explains better the behavior.
Thanks,
A.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 10:15 AM
@Alessandro Penn Whenever a new record is about to be created a function getNextObjNumberPadded is called and a number is assigned to the new record before its creation. Since the record is aborted before when the order id was empty, it wasn't stored with in the table. However, the Number counter incremented and hence the next records get a number greater than the previous number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 01:51 AM
Hi @Sandeep Rajput ,
thanks for the help, this is exactly what I was looking for.
A last question, would you know how to handle the business rule result in a script API?
(If I create a record using a Script API it returns 201 (cause the record ID is created) but the record is not actually in the table. How do I get the result of the business rule in the script? Or is there a way not to generate the record ID so I can check in the Create API if the record was actually created?)