Samarth Diamond - How to add Calculated Field in Custom Frappe Flexmonster Report
We will learn, How to add Calculated Field in Custom Frappe Flexmonster Report using Javascript Function.
·
1 min read
Add the following lines in the frappe flexmonster custom area after creating the field:
"spcustfn": {"calfield": "(function(d) { d.customfieldname=Math.round(d.reportfieldname/10,0); })"}
where,
spcustfn is just Indication of Special Custom Function (Do not change this name.)
customfieldname Just replace this by whatever name you want to give to calculated field.
reportfieldname Just replace this by whatever field you are using for calculating the calculated field.
(function(d) Do not change this.
= After equal, you can use any valid Javacript Logics to calculate field.
Advanced Example with Condition for Age Grouping:
"spcustfn": {"calfield": "(function(d) {if (d.AgeYear >= 0 && d.AgeYear <= 18){d.AgeGroup = '0-18';} else if (d.AgeYear >= 19 && d.AgeYear <= 30){d.AgeGroup = '19-30';} else if (d.AgeYear >= 31 && d.AgeYear <= 60){var interval = Math.floor((d.AgeYear-1)/10);d.AgeGroup = (interval*10 + 1) + '-' + (interval*10 + 10);} else{d.AgeGroup = '61+';};})"}
"spcustfn": {"calfield": "(function(d) { let dt = new Date(d.CheckDt_FDt).getDate(); if (dt>0){var interval = Math.floor((dt-1)/10);d.ChkDtGroup = (interval*10 + 1) + '-' + (interval*10 + 10);} ;})"}
BM
No comments yet. Login to start a new discussion Start a new discussion