Editing List View

I am trying to edit the item list view to include a button with some javascript functionality

I can test the functionality out in a Chrome Browser using a snippet and it works fine, but when I try to go through the steps to add a .js file and add it into erpnext/hooks.py it doesn’t work

I did add it as a Custom Script at first and it came up on the Items page, but not Items list.

What I have tried:
created file custom_scripts\list_items.js with below code

frappe.listview_settings[“Item”] = {
onload:function() {
$(“.page-form .flex”).append(“<button type='button' name='btnScanBarcode' id='btnScanBarcode' style='height:56px;border-width:0px;' onclick='javascript:startBarcodeScanner();'><img src='http://berrywing.com/images/barcode_2d.png' style='height: 50px; width: 50px'></button>”)

function startBarcodeScanner() 
{    
	alert("Using client JavaScript to start scanner.");
	window.location.href = 'bwstw://startscanner?field=txtField2';
}
}
}

!!— Then in the erpnext/hooks.py file I added
doctype_list_js = {
“Item”:“custom_scripts\item_list.js”
}

Also tried adding a straight javascript file to hooks.py with app_include_js and it didn’t work, when I go to the Item List source, I don’t even see a reference to the javascript file.

Any advice? I read through the hooks section, and some forum posts but I didn’t take a whole lot away, have spent 2 days trying to find a reference and testing - just trying to add a button that will open the scanning app.

Check out this link for adding button to list.js file of any doctype

1 Like