Server Script to fetch value

Hello,

I am trying to write a server script for fetching total working hours from attendance doctype as below.

System Console

a = frappe.db.get_list('Attendance',
    filters=[
        ['employee', '=' , 'HR-EMP-00014'],
        ['attendance_date', 'between', ['2023-09-01', '2023-09-30']]
        ],
    fields=['SUM(working_hours)'],
    as_list=True
)
log(a[0][0])

Its giving output as desired in System Console.

but not working in Server Script.

Server Script for Doctype Salary Slip

a = frappe.db.get_list('Attendance',
    filters=[
        ['employee', '=' , doc.employee],
        ['attendance_date', 'between', [doc.start_date, doc.end_date]]
        ],
    fields=['SUM(working_hours)'],
    as_list=True
)

doc.custom_total_working_hours = a[0][0]

Is that right method to get values in field?