Delivery note customization

when i try to make a new delivery note then get item from its getting customer information so i need it also get the items and BOM information
can anyone help me how to make this script
regards,

Hi @hemapope,

not quite clear from the question, but I am guessing you want to make a lookup when you open the form of the delivery note and fetch values? You might try something like this custom script:

frappe.ui.form.on("Delivery Note", {
  onload: function(frm) {
    // this function is called when the delivery note form is displayed
    // load related information
    frappe.call({
       "method": "frappe.client.get",
       "args": {
            "doctype": "BOM",
            "name": doc.frm.items[0].BOM  // the correct BOM reference
       },
       "callback": function(response) {
            var bom = response.message;
            if (bom) {
               frappe.msgprint("BOM: " + bom.name);
               // write value to form
               cur_frm.set_value('field_name', 'value');
            } else {
               frappe.msgprint("BOM not found");
            }
       }
    });
  }
});

Hope this helps to get your started…

@lasalesi

i made custom fields in BOM and i need these fields when i make delivery note and get item from

cur_frm.add_fetch(“BOM”, “cement_quantity”, “cement_quantity”);
cur_frm.add_fetch(“bom”, “slump”, “slump”);
cur_frm.add_fetch(“customer”, “payment_type”, “payment_type”);

i made these scripts and last one is working but the other is not working

Hi @hemapope,

addfetch will only work on items that are in your cache. This i why I had proposed to use the DB lookup, which will reliably fetch the data…

hi @lasalesi
should i put this script on the website or Linux terminal or it doesn’t matter

Hi @hemapope,

put it in a custom script for the delivery note (I guess the same place where you had the addfetch commands). This is better than modifying the delivery_note.js file, because it keeps git on the master branch and only affects the local customisation.

Hi @lasalesi ,
I was watching all the conversation above i already copy the script but can you please clear for me
where i should but the Field Name?
because i was reading the script and i didnt get where is the place i should put the reference field and the target field
thank you for your precious time

Hi @Coders,

the script will perform a database lookup on the parameters defined. In this case, it will retrieve the complete BOM record with the defined name. This is then a dict, which contains all fields. The fields can be accessed from

(frappe.call ...)
var bom = response.message;   // this assigns the response dict to the BOM (because we know it's a BOM)
cur_frm.set_value('target_field_in_form', bom.field);   // assigns the field from the bom to the target form

Hope this helps.

Hi @lasalesi

SyntaxError: Unexpected identifier
at Class.setup (http://188.166.104.18/assets/js/form.min.js?ver=1517491034.0:2641:18)
at _f.Frm.setup (http://188.166.104.18/assets/js/form.min.js?ver=1517491034.0:172:22)
at _f.Frm.refresh (http://188.166.104.18/assets/js/form.min.js?ver=1517491034.0:446:9)
at Class.load (http://188.166.104.18/assets/js/form.min.js?ver=1517491034.0:87:33)
at http://188.166.104.18/assets/js/form.min.js?ver=1517491034.0:73:10
at Object.callback (http://188.166.104.18/assets/js/desk.min.js?ver=1517491034.0:5516:6)
at Object.callback [as success_callback] (http://188.166.104.18/assets/js/desk.min.js?ver=1517491034.0:1437:16)
at _ (http://188.166.104.18/assets/js/desk.min.js?ver=1517491034.0:1461:34)
at Object. (http://188.166.104.18/assets/js/desk.min.js?ver=1517491034.0:1562:5)
at i (http://188.166.104.18/assets/frappe/js/lib/jquery/jquery.min.js:2:27151)

this msg is shown while i open the delivery note before i do anything

   frappe.ui.form.on("Delivery Note", {
  onload: function(frm) {
// this function is called when the delivery note form is displayed
// load related information
frappe.call({
   "method": "frappe.client.get",
   "args": {
        "doctype": "BOM",
        "name": doc.frm.items[0].BOM  // the correct BOM reference
   },
var bom = response.message;
cur_frm.set_value('slump', bom.field); 
 frappe.msgprint("BOM: " + bom.name);
           // write value to form
           cur_frm.set_value('field_name', 'value');
        } else {
           frappe.msgprint("BOM not found");
        }
   }
});
  }
});

the field in BOM called (slump) also in the delivery note called slump but in the delivery note i make it (read only)

Hi @hemapope,

please check your script for syntax errors, namely unexpected identifiers. Especially the doc.frm.items[0].BOM was only a placeholder, I am not exactly sure where you get the BOM-reference number from…