Role Permission, Can not access Quick Entry

I followed this guide to create a customized Quick Entry for “Delivery Trips” Doctype using client script:

Although the User has all the permissions to the “Delivery Trips” Doctype,
but i get this error.
if i disable the client script, the user can create a new “Delivery Trip” but i get an error if i enabled it.

the client script i used on “Delivery Trip” List view:

frappe.listview_settings['Delivery Trip'] = {
    refresh: function(listview) {
        listview.page.set_primary_action(__('+ Add Delivery Trip'), function() {
            add_delivery();


        });
        
    }
};


function add_delivery() {
    frappe.db.get_doc('DocType', 'Delivery Trip').then(doc => {
        let fields = [
            {
                label: __('Driver'),
                fieldname: 'driver',
                fieldtype: 'Link',
                options: 'Driver',
                reqd: 1
            },
            {
                label: __('Ordered From'),
                fieldname: 'custom_shop',
                fieldtype: 'Select',
                options: "a\nb\nc\nd\ne",
                reqd: 1
            },
            {
                label: __('Notes'),
                fieldname: 'custom_notes',
                fieldtype: 'Small Text',
            },            
            {
                fieldname: 'colbrk',
                fieldtype: 'Column Break',
            },
            {
                label: __('Vehicle'),
                fieldname: 'vehicle',
                fieldtype: 'Link',
                options: 'Vehicle',
                reqd: 1
            },
            {
                label: __('Departure Time'),
                fieldname: 'departure_time',
                fieldtype: 'Datetime',
                reqd: 1,

            },            
            {
                label: __('Address'),
                fieldname: 'delivery_stops',
                fieldtype: 'Table',
                fields: [
                    {
                        label: __('Customer'),
                        fieldname: 'customer',
                        fieldtype: 'Link',
                        options: 'Customer',
                        reqd: 0,
                        in_list_view: 1,
                        columns: 3
                    },
                    {
                        label: __('Address'),
                        fieldname: 'address',
                        fieldtype: 'Link',
                        options: 'Address',
                        default: 'Billing',
                        in_list_view: 1,
                        columns: 2
                    }
                ],
                data: []
            },
            
        ];
        
        var dialog = new frappe.ui.Dialog({
            title: __('Delivery Trip Entry'),
            fields: fields,
            primary_action: function() {
                var values = dialog.get_values();
                if (values) {
                    frappe.call({
                        method: 'frappe.client.insert',
                        args: {
                            doc: {
                                doctype: 'Delivery Trip',
                                driver: values.driver,
                                vehicle: values.vehicle,
                                custom_shop: values.custom_shop,
                                departure_time: values.departure_time,
                                delivery_stops:[{"address":"Billing"}],
                                custom_notes: values.custom_notes
                                
                            }
                        },
                        callback: function(r) {
                            if (!r.exc) {
                                frappe.msgprint(__('Delivery Trip Saved!'));
                                dialog.hide();
                            } else {
                                frappe.msgprint(__('Failed to save contact.'));
                            }
                            
                            cur_list.refresh();

                        }
                    });
                }
            },
            primary_action_label: __('Save')
        });

        dialog.show();
    });
}

I should add if i gave “System Manager” role to the use, then it works fine, i tried all other roles, none works.

1 Like

Hello :wave:,

Do one thing make a new role and then Go to role permissions manage, you can search that and select that role and Doctype on that page and give permissions according to your needs.

It will work without giving system manager access.

Thanks for the response.

I did give the “Delivery Trip” permission to “Delivery manager” role and gave that role to the user, and still getting that error.

I realized that “System Manager” has “Doctype (core)” read permission, i wonder if that is required to fix this, but there are no way to give any permission to that Doctype.

I got the problem

You are doing frappe.db.get_doc(“Doctype”

And Doctype is part of core and that why permissions issue coming…

Remove that line of get_doc Doctype

1 Like

No, that function gets 2 arguments based on Frappe Docementation:

https://docs.frappe.io/framework/user/en/api/document

frappe.get_doc

frappe.get_doc(doctype, name)

and if i remve "DocType) then i will get this error:

Brother I know that it takes two arguments but you have to remove that complete line and use this code once and try;

function add_delivery() {
    let fields = [
        {
            label: __('Driver'),
            fieldname: 'driver',
            fieldtype: 'Link',
            options: 'Driver',
            reqd: 1
        },
        {
            label: __('Ordered From'),
            fieldname: 'custom_shop',
            fieldtype: 'Select',
            options: "a\nb\nc\nd\ne",
            reqd: 1
        },
        {
            label: __('Notes'),
            fieldname: 'custom_notes',
            fieldtype: 'Small Text',
        },            
        {
            fieldname: 'colbrk',
            fieldtype: 'Column Break',
        },
        {
            label: __('Vehicle'),
            fieldname: 'vehicle',
            fieldtype: 'Link',
            options: 'Vehicle',
            reqd: 1
        },
        {
            label: __('Departure Time'),
            fieldname: 'departure_time',
            fieldtype: 'Datetime',
            reqd: 1,
        },            
        {
            label: __('Address'),
            fieldname: 'delivery_stops',
            fieldtype: 'Table',
            fields: [
                {
                    label: __('Customer'),
                    fieldname: 'customer',
                    fieldtype: 'Link',
                    options: 'Customer',
                    in_list_view: 1,
                    columns: 3
                },
                {
                    label: __('Address'),
                    fieldname: 'address',
                    fieldtype: 'Link',
                    options: 'Address',
                    default: 'Billing',
                    in_list_view: 1,
                    columns: 2
                }
            ],
            data: []
        },
    ];

    var dialog = new frappe.ui.Dialog({
        title: __('Delivery Trip Entry'),
        fields: fields,
        primary_action: function() {
            var values = dialog.get_values();
            if (values) {
                frappe.call({
                    method: 'frappe.client.insert',
                    args: {
                        doc: {
                            doctype: 'Delivery Trip',
                            driver: values.driver,
                            vehicle: values.vehicle,
                            custom_shop: values.custom_shop,
                            departure_time: values.departure_time,
                            delivery_stops: [{"address":"Billing"}],
                            custom_notes: values.custom_notes
                        }
                    },
                    callback: function(r) {
                        if (!r.exc) {
                            frappe.msgprint(__('Delivery Trip Saved!'));
                            dialog.hide();
                        } else {
                            frappe.msgprint(__('Failed to save Delivery Trip.'));
                        }

                        cur_list.refresh();
                    }
                });
            }
        },
        primary_action_label: __('Save')
    });

    dialog.show();
}
1 Like

Thanks, it worked :ok_hand:
that line was unnecessary.

1 Like