Update field in other doctype

Hi ,
im making some calculation on a sales invoice i have in accounts module but i made my own doctype as well , how can i update a field in my own doctype when calculation happens on sales invoice ?

Regards

Use frappe.get_doc in a function and call it accordingly

doc = frappe.get_doc(doctype-name, document-name)

# get property
doc.title

# set property to the document
doc.first_name = 'My Name'

# save a document to the database
doc.save()
1 Like

@vjFaLk
thanks for your response
i need this script apply to all document of that doctype not just special document
on save for each document of that doctype it should execute that script

@amirtdss whats the use case?

I think its better to relook at design… updating each document might not be the right approach…

hi, i notice the code suggest above is for server side, can teach me how to implement those code properly?

for example, i want to make a asset transfer as below

Source doctype: Transfer Asset
Source field: new_person_in_charge
Target Doctype: Fixed Asset
Target field: owner

then i want to update value from my target doctype.

var new_owner = frm.doc.new_person_in_charge;
var docname = frm.doc.fixed_asset;

doc = frappe.get_doc("Fixed Asset", docname)
doc.title     # I not sure what to type here
doc.owner = new_owner
doc.save()

I had also try the other method but does not seems to work ><

the code that I current type in my custom script as below

frappe.ui.form.on("Transfer Asset", "validate", function(frm) {
var new_owner = frm.doc.new_person_in_charge;
var docname = frm.doc.fixed_asset;
var new_docname;
frappe.client.set_value("Fixed Asset", docname, owner, new_owner)
});

Nevermind, I had found the solution that I want by referring to this