Hi,
How do I get the value of another doctype inside of my custom script?
Here is where I am at:
cur_frm.cscript.item_code = function(doc, cdt, cdn){
test = frappe.db.get_value(“Item”, “The item code”, “standard_rate”);
console.log(test);
frappe.model.set_value(cdt, cdn, “amount”, “100”);
}
How do I get the value of item_code (the item clicked to fire this function?).
our_frm.item_code ?
frm.item_code ?
Neither are working for me.
Zlash65
February 15, 2018, 4:52am
2
You can use cur_frm.doc.item_code
or since you already have doc
in the function’s parameter, you can also try doc.item_code
.
Hi Zlash65,
I have tried both of those methods and neither one are working. I am receiving undefined for both functions. Here is what I currently have:
cur_frm.cscript.item_code = function(doc, cdt, cdn){
alert(doc.item_code);
alert(cur_frm.doc.item_code);
test = frappe.db.get_value(“Item”, doc.item_code, “standard_rate”);
frappe.model.set_value(cdt, cdn, "amount", "100");
}
Zlash65
February 15, 2018, 5:06pm
4
Is the item_code a field in child table ?
If thats the case then you can fetch it through
var child = locals[cdt][cdn];
alert(child.item_code);
Hi Zlash65,
Thank you so much!!! I’ve been trying to get this variable All Day
Anyway,
I’m sure that i’m going to have lot’s of more questions as the ERPNext system seems really complex. Is this the best place to post for support related issues?
Thank you again Zlash!
1 Like
Hi Zlash65,
How do I receive the QTY item from the parent table? I am also trying to parse out the console.log(test.responseText); Is there a better way for this?
cur_frm.cscript.item_code = function(doc, cdt, cdn){
var child = locals[cdt][cdn];
test = frappe.db.get_value("Item", child.item_code, "standard_rate");
alert(doc.qty);
alert(cur_frm.doc.qty);
alert(child.qty);
console.log(test.responseText);
frappe.model.set_value(cdt, cdn, "amount", "100");
}
Hi,
I was able to get all of the values, but now am stuck on the test variable.
How do I parse the test.responseText ?
The value I am looking for is included in the responseText array.
Thank you!!!
Problem solved!
I have converted the function over to this one:
frappe.call({
method: “frappe.client.get_value”,
args: {
“doctype”: “Item”,
“filters”: {“item_code”: child.item_code},
“fieldname”: “standard_rate”
}, callback: function(r) {
if (!r.exc) {
do stuff
}
}});
Thank you for all of your help!!!
1 Like