Frappe call for whitelisted method

rappe.listview_settings["Employee Checkin"] = {
    refresh: function(listview) {
        for (var i = 0; i < listview.data.length; i++) {
            var row = listview.data[i];
            let collection = document.getElementsByClassName("list-row-container");
            var shift = row.shift;
            var emp = row.employee;
            var t = row.time;
            if (emp == 6 && shift == "shift2"){
                console.log("i am here");
               frappe.call({
			    method: "erpnext.hr.doctype.employee_checkin.employee_checkin.add_log_based_on_employee_field",
			    args: {
    				employee_field_value: emp,
    				timestamp: '06-09-2023 16:00:00',
    				device_id: 'test3',
    				log_type: '',
    				skip_auto_attendance: 0,
    				employee_field_name: emp
			    },
			    callback: function (r) {
			        console.log(r.message);
			    }
               })
            } 
        }
    }
}

any help please ??
i am trying to add employee checkin record automatically based on certain shift .
i tried to call the method add_log_based_on_employee_field but it did not work , this error comes >>

jquery.min.js:4 POST http://10.5.1.102/api/method/erpnext.hr.doctype.employee_checkin.employee_checkin.add_log_based_on_employee_field 500 (INTERNAL SERVER ERROR)
Uncaught (in promise) DOMException: play() failed because the user didn’t interact with the document first. Autoplay policy in Chrome - Chrome Developers
type or paste code here

1 Like

Hello @hayyan_daood How you resolve this issue.

I am also getting issue as below.

POST http://site.localhost:8000/api/method/my_app.my_app.doctype.my_doctype.my_doctype.update_value 500 (INTERNAL SERVER ERROR)

Below is a code in my_doctype.py

@frappe.whitelist()
def update_value(doc):
   frappe.errprint("hello")
   doc = json.loads(doc)
   frappe.errprint(f"Received doc: {doc}")

Dear @hayyan_daood

It looks like you’re encountering a couple of issues with your code.

The 500 (INTERNAL SERVER ERROR) typically indicates a problem on the server side, and

the DOMException is related to Chrome’s autoplay policy.

Let’s address these one by one.

  1. 500 Internal Server Error

This error message suggests that there might be an issue with the add_log_based_on_employee_field method call. Here are a few things to check -

My guess is - Method Path - Ensure that the method path is correct. The correct path should be erpnext.hr.doctype.employee_checkin.employee_checkin.add_log_based_on_employee_field.

My doubts on Arguments too - Verify that all required arguments are being passed correctly. The method might be expecting specific arguments that are not being provided correctly. Not sure what exactly - you may have to value add here please.

The “DOMException” related to Chrome’s autoplay policy is likely due to an attempt to play media (like audio or video) without user interaction. This can be ignored if it’s not affecting your main functionality.

I have revised the code - please check.

frappe.listview_settings["Employee Checkin"] = {
    refresh: function(listview) {
        for (var i = 0; i < listview.data.length; i++) {
            var row = listview.data[i];
            var shift = row.shift;
            var emp = row.employee;
            var t = row.time;
            if (emp == 6 && shift == "shift2") {
                console.log("i am here");
                frappe.call({
                    method: "erpnext.hr.doctype.employee_checkin.employee_checkin.add_log_based_on_employee_field",
                    args: {
                        employee_field_value: emp,
                        timestamp: '2023-09-06 16:00:00', // Ensure the timestamp format is correct
                        device_id: 'test3',
                        log_type: '',
                        skip_auto_attendance: 0,
                        employee_field_name: 'employee' // Ensure this is the correct field name
                    },
                    callback: function (r) {
                        if (r.message) {
                            console.log(r.message);
                        } else {
                            console.error("Error: No message returned");
                        }
                    },
                    error: function (r) {
                        console.error("Error: ", r);
                    }
                });
            }
        }
    }
};

Also, if it still does not work, please check the server log - with someone who knows about the logging + error messages.