Field update from list view (Action update)

Hi
Help is required in the client script for Serial no. doc type
use case:
I have a field Extended warranty expiry date which will get updated as per the Extended warranty period selected (suppose 6 or 12 months)
The following is the client script used


frappe.ui.form.on('Serial No', {
	refresh(frm) {
	function compute(doc, cdt, cdn){
   { if(doc.extended_warranty_period == "6")//it's check if the fields contains a value
        doc.extended_warranty_expiry_date = frappe.datetime.add_months(doc.warranty_expiry_date, 6);
     if(doc.extended_warranty_period === "")//it's check if the fields contains a value
        doc.extended_warranty_expiry_date = "";
     if(doc.extended_warranty_period == "12")//it's check if the fields contains a value
        doc.extended_warranty_expiry_date = frappe.datetime.add_months(doc.warranty_expiry_date, 12);
//if(x != "0")//it's check if the fields contains a value
        //doc.extended_warranty_status = "Covered";
        var x = frappe.datetime.get_day_diff(doc.extended_warranty_expiry_date, frappe.datetime.nowdate());
      if (x > 0)
         doc.extended_warranty_status = "Live";
        if (x < 0)
         doc.extended_warranty_status = "Expired";
         if (doc.extended_warranty_period === "")
         doc.extended_warranty_status = "Not Covered";
         
   }
}
cur_frm.cscript.custom_extended_warranty_period = compute;
	// your code here	// your code here
	}
})

But this works good when i open the document and update the “extended warranty period” field It automatically updates the extended warranty expiry date.

But when i try to update using the list view > action > edit> field update
it is not working.
I do this because i wanted to update 100 records in one time.

Kindly help on this

Hi there,

Client scripts are explicitly tied to events on the default web form. As a result, they won’t trigger when documents are edited in other ways. This is by design.

If you want effects like these to happen at the data model-level, you might consider using a server script instead.

Hi Peterg

Can you help with the code/script for the same. I run the site on frappe.cloud

thanks

I’m happy to help you learn. The easiest way here is probably with an scheduler script (hourly).

https://frappeframework.com/docs/user/en/desk/scripting/server-script