Try ERPNext Buy Support Partners Foundation

Issue Part List

Hi, as the title implies, we are trying to implement a part list for the Issues doctype. Currently, our custom doc Part List is a child table in the Issue doc and I am wanting to link this to Material Transfer Requests so that our Stores Manager can be notified in the system to transfer parts to the workshop.

Initially, I was trying to get the Material Request to autopopulate and submit, having all of the items generated from the Part List table, however, the Requests failed to save, citing that Mandatory Fields were blank in the Items table (without actually stating what they were), even when all fields were populated. So now I am attempting to accomplish it the other way around- the technician will fill in and submit the Request and the custom script will fill in the Part List table accordingly.

The problem that I am now facing is that I am unable to actually retrieve to access the values generated by my queries. Below is my current code in the Issue custom script

after_save: function(frm) {
    console.log("After save");
    var requests = new Array([]);
    frappe.call({
        method: "frappe.client.get_list",
        args: {
            doctype: "Material Request",
            filters: [
                ['issue', '=', frm.doc.name],
                ['docstatus', '=', 1]
            ],
            fields: ['name'],
            limit_page_length: 500
        },
        callback: function(data) {
            data.message.forEach(function(row) {
                requests.unshift(row);
            });
        }
    });
    console.log("Got requests");
    console.log('requests', requests, requests.length);
    var partList = frm.doc.part_list;
    var items = new Array(0);
    requests.forEach(function(row) {
        console.log(row, row.length);
	    frappe.call({
	        method: "frappe.client.get_list",
	        args: {
	            doctype: "Material Request Item",
	            filters: [
	                ['parent', '=', row.name],
                ],
	            fields: ['item_code', 'qty', 'ordered_qty'],
	            limit_page_length: 500,
	            parent: 'Material Request'
	        },
	        callback: function(data) {
	            data.message.forEach(function(item) {
    	            items.push(item);
	            });
	        }
	    });
    });
    console.log("Got request items");
    console.log('items', items, items.length);
},

If there’s any help that anyone can provide for handling the arrays, or if anyone has implemented a similar setup and would like to share their solution, it would be greatly appreciated.

Edit: there is an Issue link field in Material Request for linking back to the issue.