- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 09:58 PM
I have two tables in my app-Table A and Table B.
Table A is an user table ,where user can put their data and also update that in future. The fields are - Account name, Input days and Onsite/offshore.
Table B is a read-only table and not seen by the user. The fields are - Account name, Input days, Onsite/offshore, month and median rate.
So, when any records is created in Table A ,at the same time that record will be created in Table B with same account name, same input days and same onsite/offshore. But no duplicate record should not be there. The unique combination is-Account Name and onsite/offshore. The user only can update the table A by edit the input days and same change should be reflect in table B also.
So, please help me with BR for this requirement.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 11:37 PM
Please use below rectified code.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var table2= new GlideRecord('x_snc_aob_test1_dashboard_baseline_input');
table2.addQuery('account_name',current.account_name);
table2.addQuery('onsite_offshore',current.onsite_offshore);
table2.query();
if(table2.next()){
table2.baseline_input=current.baseline_input;
table2.update();
}
else{
var table2a= new GlideRecord('x_snc_aob_test1_dashboard_baseline_input');
table2a.initialize();
table2a.account_name=current.account_name;
table2a.onsite_offshore=current.onsite_offshore;
table2a.baseline_input=current.baseline_input;
table2a.insert();
}
})(current, previous);
Please mark the answer as correct and helpful.
Please mark the answer as helpful and correct.
Best Regards,
Rajat Choudhary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 10:48 PM
Table 2 and table 2a are both readonly table.
Table 2 is used to update ,table2a is used to insert. Only one will run at a time.
current keyword in business rule is automatically available which will act as the user input table.
Please mark the answer as helpful and correct.
Best Regards,
Rajat Choudhary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 11:13 PM
Hey,
Insert BR is working fine. But Update BR is not working properly. When updating a record in user table ,it creating a new record in read only table. Please check the below BR.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var table2= new GlideRecord('x_snc_aob_test1_dashboard_baseline_input');
table2.addQuery('table2.account_name',current.account_name);
table2.addQuery('table2.onsite_offshore',current.onsite_offshore);
table2.query();
if(table2.next()){
table2.baseline_input=current.baseline_input;
table2.update();
}
else{
var table2a= new GlideRecord('x_snc_aob_test1_dashboard_baseline_input');
table2.initialize();
table2.account_name=current.account_name;
table2.onsite_offshore=current.onsite_offshore;
table2.baseline_input=current.baseline_input;
table2.insert();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 11:18 PM
Hello Subhashis,
Please use below code.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var table2= new GlideRecord('x_snc_aob_test1_dashboard_baseline_input');
table2.addQuery('account_name',current.account_name);
table2.addQuery('onsite_offshore',current.onsite_offshore);
table2.query();
if(table2.next()){
table2.baseline_input=current.baseline_input;
table2.update();
}
else{
var table2a= new GlideRecord('x_snc_aob_test1_dashboard_baseline_input');
table2a.initialize();
table2a.account_name=current.account_name;
table2a.onsite_offshore=current.onsite_offshore;
table2a.baseline_input=current.baseline_input;
table2a.insert();
}
})(current, previous);
Please mark the answer as helpful and correct.
Best Regards,
Rajat Choudhary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 11:28 PM
Not resolved. After updating, new records are creating there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 11:37 PM
Please use below rectified code.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var table2= new GlideRecord('x_snc_aob_test1_dashboard_baseline_input');
table2.addQuery('account_name',current.account_name);
table2.addQuery('onsite_offshore',current.onsite_offshore);
table2.query();
if(table2.next()){
table2.baseline_input=current.baseline_input;
table2.update();
}
else{
var table2a= new GlideRecord('x_snc_aob_test1_dashboard_baseline_input');
table2a.initialize();
table2a.account_name=current.account_name;
table2a.onsite_offshore=current.onsite_offshore;
table2a.baseline_input=current.baseline_input;
table2a.insert();
}
})(current, previous);
Please mark the answer as correct and helpful.
Please mark the answer as helpful and correct.
Best Regards,
Rajat Choudhary