How to sum field total value from list of records and copy that result sum into another table field

Kishore8
Kilo Guru

Here my script:

but not working it..

Business rule: table :incident

var totalA = 0;

  totalA += current.u_used_amount;

var bRec = new GlideRecord('u-details');

bRec.query();

if(bRec.next()){

bRec.u_reaming_balance = totalA;

bRec.update();

}

find_real_file.png

8000+5000+3000=16000 , display result sum in u_details table

Table: u_details

Field: u_remaing_balance

1 ACCEPTED SOLUTION

Hi Srivastav,




(function executeRule(current, previous /*null when async*/) {


var cal = 0;


var gr = new GlideRecord('incident');


gr.addQuery('category', 'software');     // is it mandatory ??


gr.query();


while(gr.next())


cal = parseInt(cal) + parseInt(gr.u_used_amount);



var bRec = new GlideRecord('u_details');


bRec.addQuery('fieldname', 'pass the filter value here'); //if   it is new table of field then the field is empty , WHAT   DO NOW    


bRec.query();,


if(bRec.next()){


bRec.u_reaming_balance = cal;


bRec.update();


}


})(current, previous);


View solution in original post

15 REPLIES 15

Hi Kishore,



I thought my answer would be correct. 😉



anyways hope you query is solved.


Hi Srivastav,



i am requesting some modification in script here , please



Business Rule:


(function executeRule(current, previous /*null when async*/) {


var cal = 0;


var gr = new GlideRecord('incident');


gr.addQuery('category', 'software');     // ihere i as it mandatory ??


gr.query();


while(gr.next())


cal = parseInt(cal) + parseInt(gr.u_used_amount);



var bRec = new GlideRecord('sales_lead');


bRec.addQuery('fieldname', 'pass the filter value here'); //if   it is new table of field then the field is empty , WHAT   DO NOW  


bRec.query();,


if(bRec.next()){


bRec.u_reaming_balance = cal;


bRec.update();


}


})(current, previous);





here i have reference field in incident table with name portfolio values in reference table values are   FY17 SECURITY,FY17SOFTWARE,FY17 CORPORAYTE


var gr = new GlideRecord('incident');


gr.addQuery('category', 'software');       //HOW CAN I MENTION QUERY HERE


gr.query();


find_real_file.png


Field in incident table is : Protfolio(reference field , referencce table:portfolio)



find_real_file.png





SALES_LEADS -Table


Fields name:   u_fund_account_name



var bRec = new GlideRecord('sales_lead');


bRec.addQuery('fieldname', 'pass the filter value here'); //if   it is new table of field then the field is empty , WHAT   DO NOW


bRec.query();,


if(bRec.next()){


bRec.u_reaming_balance = cal;


bRec.update();


}



find_real_file.png





so how can i give values here in query condition , can you please suggest me here


Please if this helps.



1.


var gr = new GlideRecord('incident');


gr.addQuery('u_portfolio', current.u_portfolio);  


gr.query();



2.


var bRec = new GlideRecord('sales_lead');


bRec.addQuery('sys_id', 'pass the sys_id here'); //You need to check how can you pass the sys_id dynamically, is there any relation between incident and sales_lead table.


bRec.query();,


if(bRec.next()){


bRec.u_reaming_balance = cal;


bRec.update();


}


Hi Shishir Srivastava,



Here we don't have any relation between incident table and sales table ... ..



And can you please explain


addQuery(); in incident table and sales table how it will work.


Hi ,



yes, we had relation in this table.



i have 2 tables sales, and incident



in incident table - fields are there


1.u_Portfolio(reference field   - reference table is Sales table values     u_sales_dept)


2.u_used_amount



sales - fields


u_sales_dept


u_total_budget (currency field)


u_reaming_budget(currency field)




so now u_reaming_budget   =   u_total_budget   - u_used_amount





find_real_file.png


find_real_file.png