Try to set Filter in custom field

i am trying to set filter i task_name field but its not working .
frappe.call({
method:‘frappe.client.get_list’,
args:{
doctype:‘Task’,
filters:{

                'assigned_to':data.prefered_email,
            },
            
        },
        callback:function(response){
            var data_1 = response.message;
            console.log(data_1)

var taskNames = data_1.map(function(task) {
console.log(‘Task Name:’, task.name);
return task.name;
});

frm.set_query('task_name', function() {
    return {
        filters: {
            name: ['in', taskNames] 
        }
    };
});
                frm.refresh_field('task_name');

i am trying to set filter i task_name field but its not working

Try below method:

Client Side:

frappe.ui.form.on("YOUR DOCTYPE", {
	setup(frm) {
		frm.set_query("task_name", function () {
			const filters = {}; // YOUR FILTERS

			return {
				query: "PYTHON PATH OF API",
				filters,
			};
		});
	},
});

Server Side:

import frappe


@frappe.whitelist()
def get_task_searchlink_options(doctype, txt, searchfield, start, page_len, filters):
	# Update filters
	filters = frappe._dict(filters)

	if txt:
		filters.name = ["like", f"%{txt}%"]

	tasks = frappe.get_list(
		"Task",
		# YOUR CUSTOM FILTERS
	)

	if not tasks:
		return []

	search_options = []

	# customize search options

	# Return list of list (Max 3 Items In Each List)
	# Example: search_options = [["Task 1"], ["Task 2"]]

	return search_options

1 Like

How about for Multiselect field? @Abdeali

1 Like

Client Side:

frm.set_query("FIELD_NAME", () => {
  return {
    query: "API_PATH",
    params: { odd: 1 },
  };
});

Server Side:

@frappe.whitelist()
def custom_result(odd=1) -> list:
    if odd:
        return ["1", "3", "5", "7", "9"]
    else:
        return ["2", "4", "6", "8", "10"]

2 Likes

Thank you for the response