Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

Custom Script Pull Data Item List

I am working on pulling data from a delivery note to a sales invoice, but need to pull a custom field to update the sales inovice items list. I’m working with a developer to help, so i have their code below, but need assistance as i don’t have access to the database to see what the fields are. I tried looking at the doctype, but i don’t know what the primary key would be. Take a look below:

This is a custom script ran when a button is pressed on the Sales Invoice form where the Sales Invoice Items are. I want to filter the list to include just the items that are associated with the delivery note that was submitted. In the code below i’m trying to filter here: [‘name’, ‘=’, ‘DN-00109’] // test case, but the code doesn’t work. What is the field that is associated with the delivery note key? I thought it might be name, but looks as it’s not. Any help would be appreciated.

frappe.ui.form.on(“Sales Invoice”,{
test: function(frm) {{
“method”: “frappe.client.get_list”,
args: {
doctype: ‘Delivery Note Item’,
filters: [
/* [‘item_code’, ‘like’, ‘%CP%’] this should filter to delivery note. */
[‘name’, ‘=’, ‘DN-00109’] // test case
fields: [ ‘item_code’, ‘serialno’ ]
callback: function® {
for (var i =0; i < r.message.length; i++){
frappe.model.add_child(cur_frm.doc, “Sales Invoice Item”, “items”);
$.each(frm.doc.items || [], function(i, v) {

thank you.


Let me put the question in another way.

When I create a Sales Invoice from a Sales order or from a Delivery Note, the Sales Invoice populates the Sales Invoice Items or Delivery Note Items child table.

I have a custom script where i need to filter either the Delivery Note or Sales Invoice, but I don’t know how to reference. If a delivery note was passed… i could reference the items in the delivery note item by getting the parent value, but from the Sales Invoice how do i reference the child table and then the first row?

Below is what i am looking to get:




Ok… after some fumbling around I finally figured it out.

var tnum = cur_frm.doc.items[0].sales_order;