Childtable fetching from one doc to another based on Project

Hi,
I have one doctype called “Authority Approval” and another one called “Weekly Progress Report”. In both, I have one same link field "Project"and its field names are same in both doctype “project” . Also, I have childtables in both doctype, In “Authority Approval” the childtable name is “Authority Approval Table” and its fieldname is “authority_table”. In “Weekly Progress Report”, the childtable name is “WPR Authority Table” and its fieldname is “wpr_authority_table”. In both childtables, i have same fieldnames authority, authority_type, status,& remarks. Now, i need a function like, If i select any Project in “project” field of “Weekly Progress Report”, then the child table details should fetch from “Authority Approval” childtable “Authority Approval Table” to “Weekly Progress Report” childtable “WPR Authority Table”.(Note: it fetch if there is any autority approval document created for that particular project).

Now, Problem is It fetching only the even columns and also it fetch the even columns for admin user but for other user like project user it show " Insufficient permission for Authority Approval Table".I checked the permission on authority Authority Approval doctype, the permissions are already given for project user.

I attached my code below. Suggest me a solution.

There are four field ‘authority’, ‘authority_type’, ‘status’, ‘remarks’. But it fetching only ‘authority_type’,‘remarks’.

frappe.ui.form.on('Weekly Progress Report', {
    project: function(frm) {
        // Clear existing rows in the WPR Authority Table
        frm.clear_table('wpr_authority_table');

        // Get the selected project
        const selected_project = frm.doc.project;

        if (selected_project) {
            // Fetch the authority approval data for the selected project
            frappe.db.get_list('Authority Approval', {
                filters: { project: selected_project },
                fields: ['name']
            }).then((authority_approvals) => {
                if (authority_approvals.length > 0) {
                    // Create an array of promises for fetching authority table data
                    const fetchPromises = authority_approvals.map((approval) => {
                        return frappe.db.get_list('Authority Approval Table', {
                            filters: { parent: approval.name },
                            fields: ['authority', 'authority_type', 'status', 'remarks']
                        }).then((authority_table_rows) => {
                            authority_table_rows.forEach((row) => {
                                // Append rows to the WPR Authority Table
                                const new_row = frm.add_child('wpr_authority_table');
                                new_row.authority = row.authority;
                                new_row.authority_type = row.authority_type;
                                new_row.status = row.status;
                                new_row.remarks = row.remarks;
                            });
                        });
                    });

                    // Wait for all promises to resolve
                    return Promise.all(fetchPromises).then(() => {
                        frm.refresh_field('wpr_authority_table');
                    });
                }
            }).catch((err) => {
                console.error('Error fetching authority approvals:', err);
                if (err.response && err.response.message) {
                    frappe.msgprint(err.response.message);
                }
            });
        }
    }
});

Hi @Syed_Ahamed

Your code is correct. It will work fine for User who have full access of system.
But not work properly for Limited access user as you mentioned.

Reason:
Use of frappe.db.get_list or any other methods on child table check the permission in js.
Permission only set in Parent table. There is not permission for child table.

Solution:
Write a @frappe.whitelist() function in python file and fetch data from Authority Approval doctype and Authority Approal Table there

Use frappe.call to call the @frappe.whitelist() function.

How to do this ? can you please give me the code.

Can You Please check this code.