Custom Script to pull customer name to Material Request Item

Hi ERPNEXT community,

I’m trying to customise the Material Request Item for it to show the name of customer related to the Sales Order Number after I get the items from the Sales Order.

I’ve tried a few scripts found on this forum but to no avail. I’m very new to programming and don’t really know heads and tails of all the object types and functions of Javascript, but so far I’ve been able to customise quite a few things save for this one.

Basically it’s pulling a field from the Sales Order parent Doctype into a custom field in the child table Material Request Item.

Anyone has any suggestion for the script I should follow?

Thanks

Test if this works by adding this script to the “material request item” doctype?

frm.add_fetch(‘sales_order’, ‘customer’, ‘your_custom_field_in_material_request_item_to_store_customer_name’);

1 Like

Hi @aakvatech

thanks for the quick reply and help. The script you suggested didn’t work. However, I just figured out an easier way to pull the data.

  1. Create a custom field called Customer Name in the Material Request Item
  2. Data type: Data (Same as the data type in the field in Sales Order
  3. In Options enter: sales_order.customer_name

This fixes the problem beautifully. Because the sales_order field in Material Request Item is already linked to Sales Order, so I guess pull the data that’s linked to that doctype should be the same.

However, would you mind why “sales_order.customer_name” works in this case?

1 Like

This is super. Never knew this would work. Will test it out. Logically it seems the right way to get this done.

Maybe others can help.

I am not sure why the other didn’t work. It should have fetched data upon the action of “Get items from sales order”.

@Ratanak @aakvatech

I think because the the field for Customer is a Link field which seems similar to a Customer object. (If you have a look at the controller or Python code, Customer is a class) Just like in Python if you have an object you can access its attributes.

This should have been

frm.add_fetch(‘sales_order’, ‘customer**_name**’, ‘your_custom_field_in_material_request_item_to_store_customer_name’);