API and sample code for PUT Request

Hello Dears,

I am trying to update a value of a field on a doctype from another doctype using api,

i.e. I want to update a field for a given asset when a user creates an asset movement for that asset.

I have read the instruction on (Introduction) however i need the correct sample code so that I can insert in to the Custom Script of the Asset Movement.

The website above mentions usage of PUT request, but no sample code.

how can I write the code, I appreciate your snippet of code …

Can you elaborate more because this is seemingly easy via this

In python:

frappe.db.set_value("Customer", name, 'full_name', "ABC XYZ")

name is used as filter to find that specific document. In case you wish to use another field as filter then it has to be like this

frappe.db.set_value("Customer",{'account_no':'123'} , 'full_name', "ABC XYZ")

Next is the field that needs to be set which is ‘full_name’ in this context
At last is the value you wish ‘full_name’ field to have in that one particular customer.

In JS:

frappe.model.set_value(item.doctype, item.name, 'item_name', "Apple Pie");

Same goes here.

1 Like

Thank you for your kind response, please note that I am not wanting to edit the .py code, I would rather just use the js code;

So to elaborate more, in My (Asset) and (Asset Movement) documents I have added a field called (employee) to assign this asset to that employee, in which the asset would be assigned to the new employee once Asset Movement is submitted … but upon submitting the Asset Movement document I want the code to change the value of employee in the Asset document for that asset, this way I know from the Asset List which staff has currently got the asset.

Could the above be done in Custom Code of the Asset Movement with out the need to for the .py code?

I appreciate your response

Hmm. You have to use the on_submit event in Custom Script then.

Suppose, the variable denoting the Asset in Asset Movement is asset, so it should be like this:

frappe.ui.form.on("Asset Movement", {
	on_submit: function(frm){
		if (frm.doc.asset){
			"method": "frappe.client.set_value",
			"args": {
				"doctype" : "Asset",
				"name" : frm.doc.asset,
				"fieldname" : "employee",
				"value" :  frm.doc.new_assigned

Try this with your asset movement custom script

We also have a simpler abstraction of this

// in your js file
frappe.db.set_value(doctype, docname, fieldname, value)