How to auto create another Document on Project save?

Hi There,

I have a Project Type and my problem is, I want to create another DocType when I save my Project.
So when my Project type is Engine Repair then on Save I need to automatically create an Engine Repair Sheet connected to my new Project.

How can I do that in easy way?

Please help me out. Thanks.

Hi @garybsimon,

I would propose you set up a custom script on the project DocType which checks the project_type field, and on change creates a related engine repair sheet (maybe combine with set only once property of the field to prevent multiple creation). Could be something like

frappe.ui.form.on("Project", {
  project_type: function(frm) {
    // add code to create the engine repair sheet{
      method: 'myapp.myapp.doctype.enginerepairsheet.enginerepairsheet.create',
      args: {
      callback: function(r) {
        if(r.message) {
          frappe.msgprint("Engine repair sheet created.");

To create a new engine repair sheet (a custom DocType I presume), use something like this in your server-side Python

def create(project):
    new_sheet = frappe.get_doc({'doctype': 'Engine Repair Sheet'})
    new_sheet.project = project
    return { "sheet": new_sheet }

A very useful starting point is Developer Cheatsheet · frappe/frappe Wiki · GitHub.

Conditionally change the dashboard entries is probably more difficult than useful. Either make a branch and change the dashboard, or maybe add a button “Open related repair sheet”…

Hope this helps.

1 Like

How to edit Server Side for site hosted with ERPNext?

Hi @punabx,

probably not possible. Normally, you would create a new app and then install it, but you cannot do this of the hosting as far as I know. If you need custom server side code, maybe you need to check other hosting options (that is the beauty of open source software).

1 Like