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