How to write a custom func to get value for field `options'

I have no idea of how write a custom function for report filter.

Example:

frappe.query_reports['Balance Sheet'] = {
    filters: [
        {
            fieldname: 'company',
            label: __('Company'),
            fieldtype: 'Link',
            options: 'Company',
            default: frappe.defaults.get_user_default('company')
        },
        {
            fieldname: 'periodicity',
            label: __('Periodicity'),
            fieldtype: 'Select',
            options: [
                'Monthly',
                'Quarterly',
                'Half-Yearly',
                'Yearly'
            ],
            default: 'Yearly',
            depends_on: 'eval:doc.company=="Gadget Technologies Pvt. Ltd."'
        }
    ]
}

Then Instead of this

options: [
                'Monthly',
                'Quarterly',
                'Half-Yearly',
                'Yearly'
            ],

I want to write a custom function example `get_term()" which is return the list […]
options: get_term(),

Hi @treeem,

Please check it.

frappe.query_reports['Balance Sheet'] = {
    filters: [
        {
            fieldname: 'company',
            label: __('Company'),
            fieldtype: 'Link',
            options: 'Company',
            default: frappe.defaults.get_user_default('company')
        },
        {
            fieldname: 'periodicity',
            label: __('Periodicity'),
            fieldtype: 'Select',
            options: () => get_term(),
            default: 'Yearly',
            depends_on: 'eval:doc.company=="Gadget Technologies Pvt. Ltd."'
        }
    ]
}

// Custom function to get term options
function get_term() {
    return [
        'Monthly',
        'Quarterly',
        'Half-Yearly',
        'Yearly'
    ];
}

I hope this helps.

Thank You!

1 Like

Hello, I am trying to get options from an array of years that have current year and 2 last, it doesn’t work. Here is the code:

	{	
	"fieldname":"ejerc",
	"label":__("Ejercicio"),
	"fieldtype":"Select",
	"width":80,
	"reqd":1,
	"options": () => obtiene_ejercicios(),
	"default": () => obtiene_ejercicio_actual(),
	}

function obtiene_ejercicios() {
var max = new Date().getFullYear();
var min = (max - 3) ;
var Ejercicios = ;
for (var i = max; i >= min; i–) {
Ejercicios.push(i);
};
return Ejercicios;
}

Any help?, thanks