How we can include js in particular page?

Suppose I have created two j’s files (production_or.js, sales_or.js) and we need sales_or.js include only ‘new sales order page’ and production_or.js include only Production order page.

Best approach will be to use the doctype_js hook.
Reference: siyar_erpnext/hooks.py at master · consoleerp/siyar_erpnext · GitHub

Suppose I have written function (test_length) in ‘sales_order. js’ file and when we open “Production Order page” then test_length will call. How we can restrict js file load on a particular page.

Yea, thats why we have doctype_js hook.
If you specify a js file with that hook for Sales Order doctype, it will be run only when Sales Order document is open, and wont be executed when any other doctype is opened.

Pls refer the link I have given in my last answer.

@vaibhavk

Check following code. You can easily include your own js. You can also override existing feature using javascript prototype.

@fahimalizain
In this case, you need page_js hook instead on doctype_js

4 Likes

In my case, I am using page_js in hooks file and {% include “filename with path” %} in js file of a page. But still getting an error.