Server Script Update Value

Hi,

I added a Scheduler Event in the server script with a cron job. I want to update the field custom_dummy with the value “Test Dummy”.

Server Script:

def execute():

customers = frappe.get_all('Customer', fields=['name'],filters=  {'customer_name':'ABC'})    

for customer in customers:
customer_doc = frappe.get_doc(‘Customer’, customer.name)
customer_doc.custom_dummy = “Test Dummy”
customer_doc.save()
execute()

The Scheduled Job log status shows complete

[from Scheduled Job Log]

However, the field custom_dummy does not update in the Customer Doc:
image

Please guide to resolve the issue.

First of all, make sure you are getting a customer list. The above code shows that you executed your execute method after saving the doc. Create a separate function that updates the customer’s field and calls it inside the execute method.
I hope this will work.

For a better understanding, Please check the video.

How to debug in server script

in client script , we use console.log.

In server script , how to do debugging

You can check it via the console(from the terminal) or the system console.

1 Like

Sorry, code was

def execute():
   customers = frappe.get_all('Customer', fields=['name'],filters={'customer_name':'Prithvi Electronics'}) 
   for customer in customers:     
      customer_doc = frappe.get_doc('Customer', customer.name)
        
      customer_doc.custom_dummy = "dummy"              
      customer_doc.save()

execute()

Make sure the execute function is called properly by the scheduler, and remove the direct call.

Please check the video in reference post, that i provided.

You can use the print() function to print the result on the bench console.