how to check whether record exists in related list using BR

sasi
Tera Contributor

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.

 

 

12 REPLIES 12

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.

sasi
Tera Contributor

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.

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();
}

 

 

sasi
Tera Contributor

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.

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();
}