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 03:32 AM
table2 should be in single quotes.
var states = new GlideRecord('table2');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 03:37 AM
Still not working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 03:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 03:59 AM
Hi Akshay,
I have checked on incident table to get how many record has attached on task sla related list..
here is the sample code you can build same as for different related list . make sure you are aware of columns that has been used to link between those tables.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('task_sla');
gr.addQuery('task', current.sys_id);
gr.query();
var abc=gr.getRowCount();
gs.log('value of row :'+abc);
if(abc==1) {
gs.addErrorMessage("No attached outage record found");
//current.setAbortAction(true);
}
})(current, previous);
Note: Tested and it's working.