Custom Script: Unable to add new data from a custom button

Hi,

I am trying to pull the item details into the purchase order via a custom button, I have tried to copy the existing code into my custom app but there seems to be a small issue, basically the querying of the documents is fine but when I want to add data from the document, nothing seems to be happening.

Can anyone help me resolve this issue, link to the js and py file is enclosed below:

https://gist.github.com/adityaduggal/d6a8dcdaa3456c14a15870c5fe204410

https://gist.github.com/adityaduggal/dfd58ed56018c59e6e9b66597d1ecc81

I am enclosing a GIF link for what I am trying to do but the item is not getting added and there is no error as well:

@nabinhait can you help

@adityaduggal
You can not use map_current_doc as it is.

You need to fetch items from BOM selected in Production Order.
Production Order does not have items.

@adityaduggal ,

As @kolate_sambhaji suggested, you can not use mapper function for mapping parent to child doctype. You need to write a server side function to return item_code, warehouse, qty etc and then you should append those values in the item table in the callback function.

For sample code, you can refer erpnext/material_request.js at develop · frappe/erpnext · GitHub

2 Likes