Hi,
I want to run a code at a specific time,
my case is to change the item status to enable at 8 AM and change to disabled at 8 AM
Hi,
I want to run a code at a specific time,
my case is to change the item status to enable at 8 AM and change to disabled at 8 AM
Hello,
You have to make a custom app and declare a cron.
Look at hook.py of ERPNext App there is plently of sample
cron
expression is the only way but that requires custom app.
If you only want to do it with server script then use hourly job but check that you’re on 8 AM
timespan to execute your code.
Pseudocode:
if now().hour() == 8:
frappe.db.set_value("Item", ... "enabled", 0)
elif now().hour() == 20:
frappe.db.set_value("Item", ... "enabled", 1)
this code is working good but with Custom app not with Server Script
import datetime
if(str(datetime.datetime.now().hour) == 11):
item = frappe.get_doc("Item", "BC-DP-CON-1000448")
item.disabled = 1
item.save()
how I implemented in server script
You can’t use import from server script. There are a list of avaliable methods here:
https://docs.erpnext.com/docs/user/manual/en/customize-erpnext/server-script#23-security
Use this:
if(frappe.utils.format_time(frappe.utils.get_datetime(),"HH") == "11"):
item = frappe.get_doc("Item", "BC-DP-CON-1000448")
item.disabled = 1
item.save()
Hope this helps.
Server scripts also support CRON now btw