Error While creating custom Report

Hi there @shreyasp
I am trying to create a custom script report in HR Module for Attendance doctype.
But after creating it, filters are not displayed in the report so could not query any data…
Under console i checked so getting an error as report_settings is undefined.
I dont know why i am getting this error.
Can u look into the matter?

Hi after creating script report, it should add .js, and .py files
you should code it there

i Have done the coding but still the filters are not displaying so cannot query any information from the scrip…
I ll paste my .js code as well.

My Js Code:

frappe.query_reports[“Monthly Detailed Work duration”] = {
“filters”: [
“label”: __(“Month”),
“fieldtype”: “Select”,
“options”: “Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec”,
“default”: [“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”,
“label”: __(“Year”),
“fieldtype”: “Select”,
“reqd”: 1
“label”: __(“Employee”),
“fieldtype”: “Link”,
“options”: “Employee”
“label”: __(“Company”),
“fieldtype”: “Link”,
“options”: “Company”,
“default”: frappe.defaults.get_user_default(“Company”),
“reqd”: 1
“onload”: function() {
method: “”,
callback: function(r) {
var year_filter = frappe.query_report_filters_by_name.year;
year_filter.df.options = r.message;
year_filter.df.default = r.message.split(“\n”)[0];


Can you also post the .json file

Hi there,
the json file is:

“add_total_row”: 0,
“apply_user_permissions”: 1,
“creation”: “2016-11-12 14:51:05.401946”,
“disabled”: 0,
“docstatus”: 0,
“doctype”: “Report”,
“idx”: 0,
“is_standard”: “Yes”,
“modified”: “2016-11-12 16:10:57.185539”,
“modified_by”: “Administrator”,
“module”: “HR”,
“name”: “Monthly Detailed Work Duration”,
“owner”: “Administrator”,
“ref_doctype”: “Attendance”,
“report_name”: “Monthly Detailed Work Duration”,
“report_type”: “Script Report”

frappe.query_reports[“Monthly Detailed Work duration”] = {
“filters”: [

The “duration” there should be “Duration”

1 Like

Yess that was the error…
Thank you for the support.
Appreciate it.

Hi good to know that it is already solved :slight_smile: you can also right click in your browser and then inspect so that you can see the errors.

Hi there, @johnskywalker
I am currently stuck on an error.
the error is string index out of range.
but i checked all the values and dont know y i am getting it.
I ll paste my code for the same.

def execute(filters=None):
if not filters: filters = {}

conditions, filters = get_conditions(filters)
columns = get_columns(filters)
att_map = get_attendance_list(conditions, filters)
emp_map = get_employee_details()

data = []
for emp in sorted(att_map):
    emp_det = emp_map.get(emp)
    if not emp_det:

    row = [emp, emp_det.employee_name, emp_det.branch, emp_det.department, emp_det.designation]

    total_p = total_a = 0.0
    msd ="year")),int ( filters.get("month")),int (filters["start_day"]))

    for d in range(filters["total_days_in_month"]):
        status = att_map.get(emp).get((, "None")[0]
        time_in = att_map.get(emp).get(, "None")[1]
        time_out = att_map.get(emp).get(, "None")[2]
        expected_working_time = att_map.get(emp).get(, "None")[3]
        **total_hours = (att_map.get(emp).get(, "None")[4])**
        **less_time = (att_map.get(emp).get(, "None")[5])**

I am getting error on values of total_hours and less_time
msd += relativedelta(days=1)

        status_map = {"Present": "P", "Absent": "A", "Half Day": "H", "N": "", "Weekly Off":"W"}
        row.append("Status: "+str(status_map[status]) + '\n' + "In Time :" + str(time_in) + "\n"+ "Out Time :" + str(time_out)
        + "\n"+ "Expected Time: :" + str(expected_working_time) + '\n' + "Total Time Worked :" + str(total_hours)
        + "\n"+ "Less Time :" + str(less_time))

        if status == "Present":
            total_p += 1
        elif status == "Absent":
            total_a += 1
        elif status == "Half Day":
            total_p += 0.5
            total_a += 0.5

    row += [total_p, total_a]

return columns, data

@Ujjawal Hello can you post the traceback, you can find it in your console where you did “bench start”

1 Like

hi @johnskywalker,
The traceback for the error.:
Traceback (most recent call last):
File “/home/user/frappe-bench/apps/frappe/frappe/”, line 55, in application
response = frappe.handler.handle()
File “/home/user/frappe-bench/apps/frappe/frappe/”, line 19, in handle
File “/home/user/frappe-bench/apps/frappe/frappe/”, line 36, in execute_cmd
ret =, **frappe.form_dict)
File “/home/user/frappe-bench/apps/frappe/frappe/”, line 890, in call
return fn(*args, **newargs)
File “/home/user/frappe-bench/apps/frappe/frappe/desk/”, line 93, in run
res = frappe.get_attr(method_name)(frappe._dict(filters))
File “/home/user/frappe-bench/apps/erpnext/erpnext/hr/report/monthly_detailed_work_duration/”, line 36, in execute
t_h = (att_map.get(emp).get(, “None”)[4])
IndexError: string index out of range

Hi there @johnskywalker,
Any update on this?

Hello sorry, I’m a bit busy right now. Check on this later, thanks for the traceback

Sure :wink:
Thanks by the way.
Appreciate it.

Hi @Ujjawal


t_h = (att_map.get(emp).get(, “None”)[4])
IndexError: string index out of range

means that your list/array doesnt have index 4, have you checked the size and elements of your list?
try printing it first so that you may see it’s elements.

Sorry for replying late.
I have tried it and also printed all the value for the Dict.
But when printing individual values getting an error.

Hi there,
I have tried it and also solved it.
Can you just let me know how i can insert a new line in it?

row.append("Status: "+str(status_map[status]) + ‘\n’ + “In Time :” + str(time_in) + “\n”+ “Out Time :” + str(time_out)
+ “\n”+ “Expected Time: :” + str(expected_working_time) + ‘\n’ + “Total Time Worked :” + str(total_hours)
+ “\n”+ “Less Time :” + str(less_time))

i have used the above syntax to insert a new line but unable to do so what it does is it skips the ‘\n’ code and prints other

1 Like

Hi Haven’t tried doing that. But you may try <br> instead if it works. Or try doing custom jinja html, you can customize it more. Assuming that this is a custom script report, there should be a directory/files for this report, and if the name of the report is My Report you should add my_report.html in its folder. It will render what is in your my_report.html

I ll try doing that will revert back to you.

ok sure :slight_smile: