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

BALAJI40
Mega Sage

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

sasi
Tera Contributor

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".

 

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.

sasi
Tera Contributor

here i have glide with parent table?

and what will if second record is added in the related list?