Add Item name on Material Request


This is my question,
I am trying to customize my material request document by adding item_name in the material request doctype, so that every time i select item_code and Item_name from the Material request item doctype (child doctype) it would automatically pulled to the item_name field in the Material request doctype(master doctype).

I tried using the cur_frm.add_fetch(‘item_code’,‘item_name’,‘item_name’) on custom script but its not doing any effect.

can you helped me and thanks for your help

The Material Request can have more than one Material Request Item. How are you planning on handling more than one item?

I think something like this should work:

   frappe.ui.form.on('Material Request Item', 'item_code', function(doc,cdt,cdn)
    //Get the local variables of the child table (cdt) with the corresponding child name (cdn)
    var d=locals[cdt][cdn]{
                "method": "frappe.client.get_value",
                args: {
                    'doctype': 'Item',
                    'filters': [['Item', 'item_code', '=', d.item_code]],
                    'fieldname': 'item_name'
                callback: function (data) {
    frappe.model.set_value(doc.doctype,doc.docname,"item_name",  data.message.item_name);
    //Refresh the table

Hi Ben,

I tried your code in the custom script-material request but its still not

i am sorry as i am still new in frappe,

could you give me more detailed instructions of what should i do

attached are print screen of what do i want to make the customization look

thanks again for your patience

i hope i can learn fast



Ps: i am using the production planning tool often, so the material request
generated are always 1 item 1 document. the idea was to put item name in
front of the material request form
so i can filter based on the item name/item code. so that the material guy
would have better understanding when he choose the material form with name
on it.


This seems like a very bad way of solving your problem. Why don’t you just use the report function, include the Item Name and Item code from each item as a column (Using the Menu > Pick Columns) and then sort by that column?

Hi Ben

Sure I can do that,

Its just i am curious now, as this problem looks easy but i cant solve it

As i am still learning on frappe, i hope i can get the solution to fetch
value from child doctype to master doctype using custom script.

as i will encounter this problem again i think in future.

can you help me with this
thanks again and sorry to bother


Can you let me know what is happening when you try to run the script I provided? What error do you get? Look at the Developer Console on your browser and it should show an error when you load the doc.

@ Ben_Cornwell,

Dear Sir,

Thanks for your help, finally i am able to run your script and it works,
There is just some misunderstanding on how the script works as i tried to fetch the item code
on the child doctype and to show it on the master doctype.

the script work when i fetch the item_code on the child doctype and to show it on the child table.

Thanks and best regards sir