Get row count for related list business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 03:23 AM
Hi,
I want to create a business rule that aborts the insertion/updation of a record to the table, if no record is added in the related list.
Base table-table1
Related list(child table)-table2
created a business rule on table1 with a that should work when certain entries are selected for a field state(choice type).
Please check the following script if any corrections are required in it?
(function executeRule(current, previous /*null when async*/) {
var states = new GlideRecord(table2);
var ns = states.getRowCount();
if(ns==0)
{
addErrorMessage(states , "No record should created");
states.setAbortAction(true);
}// Add your code here
})(current, previous);
Kindly let me know if any other possible ways are also there for this requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 04:19 AM
Hey Harsh,
Thanks I got the point that the record needs to be queried first to get the count.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 04:23 AM
Just want to bring in one point,code works fine now the only problem is when i remove all the items from related list and then i try submitting the record.It actually accepts that.
Is there any possibility that we can add a condition to this as well and do you know why this happens?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 04:29 AM
just because your business rule has written on parent table and you did the operation on child table that's why business rule did not check if you had removed or added record in related list.