Addition of two values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 03:44 AM
I have scenario where i have 2 tables, Each table consists of two columns with the same name that is "Parameter and Value"
Each table have some data like....
IN first table data is like below IN second table data is like below
Parameter value Parameter Value
XYZ 20 XYZ 9
ABC 30 ABC 4
Now i want to calculate first table value with second table like as below...
(1st table value)20 + 9(Second table value) = 29
30 + 4 = 34
Now i want to paste this output in another table which i have already created, It is shown as below...
Parameter Value
XYZ null( in place of null i want to paste the value as 29)
ABC null ( in place of null i want to paste the value as 34)
please suggest me the business rule for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 05:05 AM
Hello @RERA02
Write this Background Script for doing :-
var a = new GlideRecord('table A');
var b = new GlideRecord('table B');
var c = new GlideRecord('table C');
a.query();
b.query();
c.query();
var res;
while(a.next() && b.next() && c.next()){
res=a.value+b.value;
c.initialize();
c.updateRecord('value',res);
}
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 05:12 AM
Hi @RERA02 ,
Use below script
(function executeRule(current, previous) {
var table1 = new GlideAggregate('table1');
table1.addQuery('field', 'XYZ'); // Customize the query as needed
table1.query();
var table2 = new GlideAggregate('table2');
table2.addQuery('field', 'XYZ'); // Customize the query as needed
table2.query();
var sum = 0;
while (table1.next() && table2.next()) {
sum += parseInt(table1.getValue('Value')) + parseInt(table2.getValue('Value'));
}
var table3 = new GlideRecord('table3');
if (table3.get('field', 'XYZ')) { // Customize the query as needed
table3.setValue('Value', sum);
table3.update();
}
})(current, previous);
Please mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 10:45 PM
Hi Anand,
Thanks for your solution, Actually it is not showing the result as what i mentioned in question, Could you please suggest me another solution .