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 04:47 AM
If you are writing before the business rule, the below line return as false because there are no records.
if (!gr.hasNext()) {
From the second time onwards, it returns as true and hence it won't go inside the loop.
Hope you understand my point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 05:03 AM
yes i got it thank you,
there is a field called "initial review" true/false check box field in related list table. when there is a second record is added, it has to update in the parent table type field from related list only when ""initial review" as true.
finally when first record is added update type from related list to parent table
then second record is added check for "initial review" is marked as true or not then update only that value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 05:29 AM
Hi,
Create an after business rule and set the condition as intial review as true
var gr = new GlideRecord("table_name");
gr.addQuery("parent", current.parent.toString()); // set the condition
gr.query();
if (gr.getRowCount== 2 && current.internal_review) { // map correct fiels
var par = current.parent.getRefRecord();
par.field_name = current.internal_review.toString(); // map the correct field
par.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 05:57 AM
Now i have written two business rules, one is the first which you have given above when there is no record show error message
other business rule to update the record in parent table
it is working as expected but, error messge is also coming it should show only when there is no record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 06:17 AM
Hi,
Let's change the second business rule to after and try this script with an order of 1001.
var gr = new GlideRecord("table_name");
gr.addQuery("parent", current.parent.toString()); // set the condition
gr.query();
if (gr.getRowCount== 1) { // map correct fiels
var par = current.parent.getRefRecord();
par.field_name = current.type.toString(); // map the correct field
par.update();
}
if (gr.getRowCount== 2 && current.internal_review) { // map correct fiels
var par = current.parent.getRefRecord();
par.field_name = current.internal_review.toString(); // map the correct field
par.update();
}