How to save and update and save the doctype.?

In the below code when one add a row in childtable (risk_location) from fire doc and save it, the data iterate into a code and get assigned to the result_code field,but result_code didn’t get updated in fire table with the assigned values…so when i refresh the result_code field values get disappered. how to save it again…to avoid the values getting disappered.

import frappe
from frappe.model.document import Document

class Fire(Document):

    def on_update(self):
        self.template_string()

    def template_string(self):
        parent = self.name
        data = frappe.db.sql(f""" select risk_location_address , value from `tabRisk Locations` where parent = "{parent}";""".format(),as_dict=1)
        if data:
            template = "<tr><td>{}</td><td>{risk_location_address}</td><td>{value}</td></tr>"
            replace = ""
            line = 1
            replace_str = []
            for d in data:
                replace = template.format(line,**d)
                replace_str.append(replace)
                line += 1
                result_code = " ".join(replace_str)
            self.temp_code = result_code

I again call that function when loading so the field assigned to the value at the time of refresh even though it didn’t get saved but its enough for me to get the desired goal! :cowboy_hat_face:

def onload(self):
    self.template_string()