Business rule to compare between two different fields in two different tables.

test1231998
Tera Contributor

I wanted to write a business rule to compare between 2 different fields on 2 different tables.

I have 2 tables table_1 and table_2 with fields total_days and working_days.

The total_days field in table_1 should be less than working_days field in table_2

So whenever I create new record from table_2 if the above condition is not met then the request shouldn't be submitted.

 

 

6 REPLIES 6

Hi Reshma.Thanks for your help

No there is no fields in table_2 referencing to table_1

Both of the fields are of type integer

reshmapatil
Tera Guru

Hi Deepika,

 

So if table_1 and table_2 are not related anywhere then we can use the about code.

If you want to check working_days from table_2 with multiple records in table_1

use:

var gr = new GlideRecord(Table1);

gr.addEncodedQuery('total_daysISNOTEMPTY');  //can add more filters as per your need

gr.query();

while(gr.next()){

// If working_days is greater than total_days field

if(gr.total_days>current.working_days)

// or can use if(parseInt(gr.total_days) > parseInt(current.working_days))

current.setAbortAction(true);

else{

//set field values which you want to populate during the insertion on record in Table2

}

}

 

Please mark correct & helpful if that works for you.

Thanks.