Business rule to compare between two different fields in two different tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 09:58 AM
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.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2020 10:56 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2020 10:13 AM
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.