how to check whether record exists in related list using BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 03:32 AM
Hi ,
i want to check whether there is at least one record in related list , if it is there fine. if there is no record show error message that as "please add one record at least"
and these check has to done when it is changing from new to work in progress.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 03:40 AM
Hi,
You can create a before business rule and set the condition as the state is changes from new to changes to work in progress
The script should be something like this.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("table_name");
gr.addQuery("parent", current.getUniqueValue()); // set the condition
gr.query();
if (!gr.hasNext()) {
gs.addErrorMessage('Rejecting');
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 03:53 AM
Thank you it is working for me,
i have another requirement on the same in the related list table there is a field called "type" the first record of the type value i want to update on the parent field called "Parent Type".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 04:29 AM
Hi,
Then in that you to write a before business rule on related list table and mention the script like this,
var gr = new GlideRecord("table_name");
gr.addQuery("parent", current.parent.toString()); // set the condition
gr.query();
if (!gr.hasNext()) {
var par = current.parent.getRefRecord();
par.field_name = current.type.toString(); // map the correct field
par.update();
}
Since my answer is helpful, can you mark my response as correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 04:43 AM
here i have glide with parent table?
and what will if second record is added in the related list?