Custom Script Name

Hi guys,

For current system, the Custom Script name is tight to a DocType.
This makes it impossible to have 2 Custom Scripts for the same DocType in a system.

Imagine I install 2 different apps, both need to have Custom Scripts on the same DocType.
This will not work right ? So why need to keep its name tight to the DocType ?

Should I just go to DocType Custom Script and adjust this ?

Thank you!

Try adding code to doctype via app hooks

https://github.com/frappe/frappe/blob/develop/frappe/widgets/form/meta.py#L70

Check this out.

You can add hook in your custom app to add js code to doctype

doctype_js = {
    "Sales Order": ["yourapp/cscript_to_sales_order.js"]
}

I have not tried it myself, just stumbled upon while reading code. Hope it helps.

Do update on forms if it works.

2 Likes

Hey BhupeshGupta,

Thank you! It actually works. Just a highlight, the path is relative to the app where you put that hook. For example, the app structure is:

myapp
-- myapp
---- hooks.py
---- custom_scripts
------ salary_slip_custom.js

The hook will be just:

doctype_js = {
    "Salary Slip": ["custom_scripts/salary_slip_custom.js"]
}

Just reload server and it will work. This way will be much nicer to develop apps rather than use Custom Script as a fixtures.