In my scenario, the users are linked to warehouses. So there is a custom link field for User. In Sales Order, I need to change items’ warehouse to user’s warehouse. Right now the only way I found to get the user’s warehouse is the function frappe.db.get_value.
To make it easy to understand and to exclude other possible problems, here I will take fetching the user’s full_name instead of warehouse as an example.
I put the test script in Custome Script as following:
var req = frappe.db.get_value(“User”, {“name”:frappe.session.user}, “full_name”);
console.log(req);
var jsonResponse = req.responseText;
console.log(jsonResponse);
In the console it shows req is a response object:
{…}
abort: function abort()
always: function always()
complete: function add()
done: function add()
error: function add()
fail: function add()
getAllResponseHeaders: function getAllResponseHeaders()
getResponseHeader: function getResponseHeader()
overrideMimeType: function overrideMimeType()
pipe: function then()
progress: function add()
promise: function promise()
readyState: 4
responseJSON: {…}
message: Object { full_name: “Alvin Chen” }
proto: Object { … }
responseText: “{“message”:{“full_name”:“Alvin Chen”}}”
setRequestHeader: function setRequestHeader()
state: function state()
status: 200
statusCode: function statusCode()
statusText: “OK”
success: function add()
then: function then()
proto: Object { … }
The returned object is right, and the right information is there. The problem is that I can not get the property with member operator.
The output of console.log(jsonResponse) is “undefined”.
Actually any other member is also not accessible.
How can I access the members of the response?