Dashboard: how to enable adding related record

I have a new DocType with a dashboard. I have managed to get the related DocTypes to show on the dashboard.

However, how to I enable the “plus” button to directly create a related record?

This is what it looks like:

And I want to achieve something like the dashboard on Customer.

Any help is appreciated!

Then simply check

If you want to create a dashboard for your doctype just create doctype_dashboard.py same as customer_dashboard.py in doctype’s folder itself.

Check dashboard.js to know more about it’s working

1 Like

Dear Sangram,
many thanks for your response. I guess where I am stuck is here:

after_refresh: function() {
     var me = this;
     // show / hide new buttons (if allowed)
     this.links_area.find('.btn-new').each(function() {
        if(me.frm.can_create($(this).attr('data-doctype'))) {
          $(this).removeClass('hidden');
        }
     });
},

My question is why is “can_create” not set? If I click the “Technical data sheet” link, it opens the list view of that DocType with the correct filter and I can add a related record (therefore I believe it cannot be an access right situation). But, the (+) sign does not show in the dashboard.

If I insert one of my DocTypes on the customer_dashboard.py it does show a plus sign to directly create a related record.
from frappe import _

def get_data():
    return {
        'heatmap': True,
        'heatmap_message': _('This is based on transactions against this Customer. See timeline below for details'),
        'fieldname': 'customer',
        'transactions': [
            {
                'label': _('Pre Sales'),
                'items': ['Opportunity', 'Quotation', 'Crono']
            },
            {
                'label': _('Orders'),
                'items': ['Sales Order', 'Delivery Note', 'Sales Invoice']
            },
            {
                'label': _('Support'),
                'items': ['Issue']
            },
            {
                'label': _('Projects'),
                'items': ['Project']
            }
        ]
    }

But this does not show the plus:
from frappe import _

def get_data():
    return {
        'fieldname': 'crono',
        'transactions': [
            {
                'label': _('Information'),
                'items': ['Technical data sheet', 'Sample identification']
            },
            {
                'label': _('Tests'),
                'items': ['Bunsen burner test', 'Ladder test', 'Smoke test', 'Accidity test']
            },
            {
                'label': _('Reports'),
                'items': ['Factory inspection', 'Classification', 'CoC']
            }
        ]
    }

Do I need to enable “can_create”? What am I missing?

Many thanks for any clue!

I encountered the same problem. I think there are two possible reasons. First, the user does not have permission to create the related documents. Second, does your doctype allow submit? If so, the document can only create related document when it is submitted.

2 Likes

Hi @bananayoyo,

thank you for your response. You are exactly right, in this case it was a submittable doctype, which only allowed the “+” once it was submitted. As the references documents should already be attached before submit, I have made the doctype not submittable, and it worked :wink: