Error in server script while save

Hi …A lot of time i tried to write server script.Issue i’m facing in that is i can’t save doc if i wrote a code to show a message in after save,But my message will show . What is the reason behind this?

Hi @Shahina_K,
If you just need to show a massage then you should use frappe.msgprint() instead of frappe.throw(). Throw is used to generate an exception.

For more just refer : Python Dialog API

Thanks sherin. My exact requirement is,i want to call a list of doc and update its status.I tried below code
for fpr in frappe.db.get_list(‘Task’,filters={‘status’: ‘Open’}):
if fpr:
frappe.throw(“doc exist”+fpr.name)
fpr_doc = frappe.get_doc(“Task”, fpr.name)
if fpr_doc:
fpr_doc.status=“Overdue”

Why using frappe.throw()? For updating the status it’s enough.

for fpr in frappe.db.get_list(‘Task’, filters={‘status’: ‘Open’})
if fpr:
fpr_doc = frappe.get_doc(‘Task’, fpr.name )
fpr_doc.status = “Overdue”
fpr_doc.save()

Please check my code .I already tried these codes.Due to error to check out i added frappe.throw

Oh, Here the problem is, it’s working recursively. Because On after save of task another task is also getting updated, it will recursively happen.

So what should i do to correct this?
My actual requirement is to check due time and to change status into overdue if employee not completed task on time. so i have to write this code in scheduler event ,to check whether it is working or not i wrote this in doctype event.Please help

Check like this, it will update directly to db.

for task in frappe.db.get_list('Task', filters={ 'status':'Open'):
     if task:
        frappe.db.set_value('Task', task.name, 'status', 'Overdue')
frappe.db.commit()

In which event Scheduler or in doctype

You can use as per your requirement.

Ok …checked…New error is module has no attribute"commit"

Hi @Shahina_K,

Please try and hope this some help you .

if doc.status == "Open":
    doc.status = "Overdue"

Thank You!

Hi…But i want to change status of all doc into Overdue if exceeded due time

Thanks sherin…Got out.I removed frappe.db.commit() line from your code to solve error module has no attribute “commit”.