How do I stop virtual doctype linked field to search into database?

I have link virtual doctype into another doctype and the data in the virtual doctype is mapping with external api. Now when I type in the linked field it searches in the frappe database, so how to stop that and write our own method to handle that?

@Harsh_Shiroya There’s an undocumented API for this in hooks.py and an example in ERPNext’s hooks:

This query API must match the query API that link docfields support, which is well documented.
https://frappeframework.com/docs/v14/user/en/guides/app-development/overriding-link-query-by-custom-script#custom-method

I am using external api to get data. For eg:

@frappe.whitelist()
def get_customer_list(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
    

    url = api_of_customerlist
    headers = {'applicationcurrentkey': ak,'Authorization': bt}
    response = requests.get(url, headers= headers, verify = False)


    if response.status_code == 200:
        data = response.json()
        customer_data = data
        cust_data = []
        cdd = []
        for i in range(len(customer_data['data'])):
            c = (customer_data['data'][i]['mfgCode'],customer_data['data'][i]['mfgName'],customer_data['data'][i]['id'])
            cust_data.append(cd)
            cdd.append(c)
        
        return cdd
    else:
        return None

I have tried to return the tuple as the database would but its not working.

@Harsh_Shiroya Try returning an empty list instead of None. You may have to restart your bench in order to pick up the standard_queries change.
Here’s a proof of concept implementation I did using a CSV as the data source. There are artifacts of loading the entire CSV in here, mostly in pagination. I am also not handling the txt or filters arguments at all.

@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def facility_query(doctype, txt, searchfield, start, page_len, filters):
	listview = []
	with open((Path(__file__).parent / 'NASA_Facilities.csv').resolve()) as csvfile:
		reader = list(csv.DictReader(csvfile))
		for index, row in enumerate(reader):
			_row = [index]
			_row.extend([row.get(frappe.unscrub(f)) for f in frappe.get_meta('Facility').search_fields])
			listview.append(_row)
		return listview[int(start):(int(start) + int(page_len))]
1 Like

@tmatteson Is this code enough for you to handle the search and selection of value in the link field?
Because when I use the above code it shows the list but it doesn’t search for the typed value and when selecting a value it doesn’t select the particular value instead it runs

POST /api/method/frappe.desk.search.search_link HTTP/1.1

this method and executes the query to lookup the data in database which will be not found for the virtual doctype.
And also I confirmed by print statement that the get_customer_list is called by standard_queries.

No, that’s what I meant by " I am also not handling the txt or filters arguments at all."

Then how do I handle that for my code?

And its still not letting me select the value in the field. How can I implement this?