I tried to access data from Child Tabe of other DocType to the Current Doctype. How to make it?

I am using client script to the User doctype. Here, I want to access the data of child table Doctype Email And Site which has parent Doctype Support User Branch Setting. I want to delete the row in the child table if the email from User’s email matches the user_email (field_name of child table) and has no role for Support Team from that row after saving the doc.

Please see the code below.

frappe.ui.form.on('User', {
    after_save: function (frm) {
        if (frm.doc.name && frm.doc.roles) {
            var isSupportTeam = false;
            for (var i = 0; i < frm.doc.roles.length; i++) {
                if (frm.doc.roles[i].role === 'Support Team') {
                    isSupportTeam = true;
            if (isSupportTeam) {

                    method: 'frappe.client.get_list',
                    args: {
                        doctype: 'Email And Site', //child Table of Support User Branch Setting
                        filters: {
                            parent: 'Support User Branch Setting'// 
                        fieldname: ['user_email'] 
                    callback: function(response) {
                        if (response.message) {
                            // Process the retrieved data
                            var childTableData = response.message;
                            for (var i = 0; i < childTableData.length; i++) {
                                var childRow = childTableData[i];
                                var field1Value = childRow.user_email;
                                // Do something with field1Value and field2Value
                                console.log("Field 1 Value: " + field1Value);
                                console.log("Field 2 Value: " + field2Value);



I got an error after saving the doc
Screenshot from 2023-10-02 12-29-19

@Prasant_Pant why are you using client scripts to do so ? a server script would be much easier and safer

@bahaou could you help me out by providing server script? Thanks

@Prasant_Pant create new server script select event after save and just translate your code to python .
here are documentation

1 Like