How to Get List of Documents Using List of Document Names?

In javascript I have a list of document names for a known doctype. I want to do db.get_list() to fetch all documents matching my list of document names.

How is this done?

You can use this as an example.

frappe.call({
  method: 'frappe.client.get_list',
  async: false,
  args: {
      'doctype': 'Purchase Taxes and Charges',
      'parent': 'Purchase Taxes and Charges Template',
      'filters': {
          'parent': tax_template,
          'parenttype': 'Purchase Taxes and Charges Template'
      },
      'fields': [
          'add_deduct_tax',
          'included_in_print_rate',
          'rate',
          'account_head',
          'description'
      ]
  },
  callback: function(r) {

  }
});

I’m not sure you understood my issue.

Assume I have a list of names for documents of type ‘Purchase Taxes and Charges’. I want to retrieve all of the documents with those names.

How do I do that?

You may want this.

frappe.get_list('Purchase Taxes and Charges', {'name': document_name});

Create a server script with a type of API where the response is the data that you want
then call it on your client script via frappe.call().

const doc_list = await frappe.db.get_list("Item", {
    fields: ["item_group", "item_name"],
    filters: {
        "name": ["in", ["itemname1", "itemname2"]]
    }
})

This essentially converts to backend SQL query:

select item_group, item_name 
from `tabItem` 
where name in ("itemname1", "itemname2") 
--- + some permission checking code 

get_list only gives you fields on that doc, if you want full doc objects use get_doc

2 Likes

Your Try like this also

this is the output while print

this is list

try frappe.db.get_value or get_doc as per use case

docList = ['Input GST Out-state','Input GST In-state']
for i in docList:
    list_taxes = frappe.db.get_value('Purchase Taxes and Charges Template', i, 'name')
    frappe.msgprint(list_taxes)

@ankush

Thank you!

This is exactly what I needed. There aren’t any documented get_list examples demonstrating the use of sql ‘in’ or even passing an array of values. It’s good to see this is fully supported.

2 Likes