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 and an example in ERPNext’s hooks:

This query API must match the query API that link docfields support, which is well documented.

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

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'])
        return cdd
        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.

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])
		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/ 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?