Best way to manage client scripts on core doctypes

I’ve recently moved all of my custom doctypes to a new app, which is all backed up to github. The client scripts that I had created in ERPNext have all been moved over to my custom app’s source code… all apart from 2 scripts, which are for core modules (Customer, and Address).

I’m wondering what the best practice is for working with scripts for core doctypes? The reading I’ve done suggests that one shouldn’t make changes to core doctypes (customer.js, for example) as changes will be lost when you update ERPNext.

Is there a way to manage my customer and address scripts so that I can pull/push changes to git like I do with my custom app?

Many thanks!

You can use hooks in the custom app to load your javascript files for core doctype. Refer javascript files

Also Check Client Script

1 Like

Perfect. Thanks @mujeerhashmi, I’ll check these links out. :100:

For anyone else with this query…

I un-commented the following in, and dropped my custom scripts in the .js file

app_include_js = "/assets/rv_app/rv_app.js"

Cheers @mujeerhashmi!

1 Like

That’s not the reason people advise against it. You can definitely make changes to core DocTypes without losing them during updates. You just have to be willing to spend time doing git merging. It’s the savings in time + effort that fuels these suggestions.

But for anyone who’s previously worked with an ERP using a compiled programming language? Merging code modifications is a fact of life, and the -only- way to upgrade.

Frappe/ERPNext are able to skip this step(*), because they’re based on a pair of interpreted programming languages: Python and Javascript. This introduces some interesting tricks, which are used with advantage by, Customization, Server and Client scripts, etc. They allow us to split the code into different places: original, appended, and overwritten.

There are both advantages and disadvantages to this approach. It potentially saves a lot of time, and makes concepts like App Stores much easier. But it can also introduce unexpected runtime errors, and makes it difficult to clearly see the entire code set.

1 Like

Thanks for taking the time to clarify those distinctions @brian_pond, much appreciated.

I’ll look into git merging and see if it’s worth the effort for my use case.

Cheers mate!

1 Like

Hi all… running into a problem with my prod environment.

I’ve made changes to the js file I’ve got in my custom app, which applies changes to core doctypes (customer, address etc). As above, I’ve included this script in the file for my custom app, however I can only see the changes applied when I move back to development.

I’ve tried:

bench migrate
bench build
bench clear-cache
bench clear-website-cache
bench restart
bench restart --web
bench supervisorctl start/stop all
sudo reboot

I’ve also tried pushing/pulling from git and reinstalling my custom app.

I’ve done a lot of searching on the forum and the above solved this issue for many people, however it’s not working for me. Not sure what I’m missing :frowning:

Any suggestions on how to have these changes stick in my prod environment would be appreciated.

1 Like

Hi @Shaun,

According to documentation here and here, it appears that app_include_js is only used for overriding Desk Assets and desk.html.

For modifying specific DocTypes, there’s doctype_js and doctype_list_js. Here’s a snippet from a that I manage:

Are you using this same syntax?

doctype_js = {
	"Customer" : "public/js/patch_customer.js",
	"Item":      "public/js/patch_item.js",
	"Journal Entry": "public/js/patch_journal_entry.js"

doctype_list_js = {
	"Item Price": "public/js/patch_item_price_list.js"

When it comes to JS modifications, usually 'bench build' and restarting the web service is all that’s required.

1 Like

Thanks for the info @brian_pond, I’ve changed my to your syntax and it’s working as expected now!

Many thanks