Try ERPNext Buy Support Partners Foundation

Is it possible to use 'Server Script' without creating a custom app?

HI everyone, below is a doctype I have created. My question is how can I fetch the child table from the selected ‘Job Interview Template’?

Can I use ‘Server Script’ without creating a custom app? i.e. using @frappe.whitelist method in Server Script & Custom Script

It should work similarly to Appraisal Template.

  • picked from appraisal.js
  kra_template: function(frm) {
		frm.doc.goals = [];
		erpnext.utils.map_current_doc({
			method: "erpnext.hr.doctype.appraisal.appraisal.fetch_appraisal_template",
			source_name: frm.doc.kra_template,
			frm: frm
		});
	},
  • picked from appraisal.py
@frappe.whitelist()
def fetch_appraisal_template(source_name, target_doc=None):
	target_doc = get_mapped_doc("Appraisal Template", source_name, {
		"Appraisal Template": {
			"doctype": "Appraisal",
		},
		"Appraisal Template Goal": {
			"doctype": "Appraisal Goal",
		}
	}, target_doc)

	return target_doc

I believe there are still many users in the community like myself which have yet to fully understand this new feature, Server Script. Your guidance would be greatly appreciated. Thank you in advance. :grinning:

Anyone?

I’ll answer the best I can:
Technically yes, everything is possible.
That being said, you’ll have a major issue when you will update/upgrade your frappe/erpnext version. You might loose every changes you made because all of those changes will be in frappe/erpnext folders. You could always merge your changes with theirs, but I don’t garentee it will work as you expected.

You could also write a custom script (js only) in ‘Custom Script’ Doctype. This code is in the DB instead of frappe/erpnext directory. The downside of this option, is that if something happen to your server (ex: bench migrate), you’ll loose that custom script. Which is quite a big downside honestly. To keep it, you need to add it to public/yourapp.js or add it in hook.py as a fixtures.

Is there a reason why you don’t want to create a custom app?
With a custom app, you’ll gain so much more freedom regarding those kind of changes.

2 Likes

I think that you can use the “API” form of the doctype “Server Script” to create the python whitelisted method. And the “Custom Script” doctype to create the JS part. They are not going to be deleted on a migrate. They work like every doctype, for example, the customers are not deleted in a migrate. You are going to lose it if you do a bench reinstall for example.

2 Likes