How to use frappe.utils methods in server script

How to use frappe.utils methods in server script

Here Server Script are instructions for server script

I tried to write for example frappe.utils.nowdate() and frappe.utils.data.nowdate() ,but I get error

Is there any another syntax to write a frappe.utils methods

Thanks in advance

share what you have done so far

Try this
frappe.datetime.now_datetime() , frappe.datetime.get_today()

frappe.utils.nowdate() should work. Can you please share the error?

@nabinhait
TypeError: ‘NoneType’ object is not callable


submitted_on is a custom field.

Hello @alkuhlani,

I am facing this same problem, have you found any solution?

Regards,
Vishakha Mishra

1 Like

No :cry:

1 Like

I think now it is working.

How?
I can’t use frappe.utils.xlsxutils.read_xlsx_file_from_attached_file()

@indrawow Due to security issues, only selected methods are available in the server script.

https://docs.erpnext.com/docs/v13/user/manual/en/customize-erpnext/server-script#25-security

To anyone looking to manipulate dates from within a Server Script, the following is an example of how to jump momentarily from the safe, impossible-to-do-any-harm zone of the Python sandbox into the safe, impossible-to-do-any-harm zone of your entire corporate database:

def getThisMonthRange():
    data = frappe.db.sql("""
                SELECT LAST_DAY(now()) AS last_day
              , DATE(date_add(now(),interval -DAY(now())+1 DAY)) AS first_day;
           """, 
           as_dict=True)
    return data[0]

date_dict = getThisMonthRange()
firstOfMonth = date_dict.first_day
endOfMonth = date_dict.last_day