How to compare fields of two different doc

Hi All ,

Could anyone just let me know on how to do this

compare a field from Doctype A with a field in Doctype B .

Thanks in advance

cur_frm.add_fetch(‘B’,‘y’,‘y’);

B is your Doctype B which is also a linked field in your Doctype A.
The first y is the source field you want to copy (Doctype B).
The second y is the target field which you will copy to (Doctype A).

function compareXY(c,d)
{
var result = (d - c);
return result;
}

Create your compare function that accepts 2 variables.
The c and d will accept your variables(x from Doctype A, y from Doctype B).
Do what you need inside the function(comparisons,equations).
Return the result you want.

frappe.ui.form.on(“A”, “x”, function(frm)
{
cur_frm.set_value(“z”,compareXY(frm.doc.y,frm.doc.x));
}

When you interact with the field x on Doctype A it will call the function to do the comparison/equation (since your Doctype A will have the x and y values already) and put it in field z.

1 Like

In my custom script of sale order i want to compare current_time of sales order(doctype1) to order_locking _time of my app setting doctype(Dairy Setting)(doctype2). by doing so i want to validate the doctype1 form
method to do so.

@asinghdxc Can you explain your case. ?

i figured it out.
can u tell how can i access single doctype field value in custom script?
i want to fetch that value and store inside a variable.

value = frappe.db.get_single_value("Doctype ", ‘field Name’)
e.g
precision = frappe.db.get_single_value(“System Settings”, ‘float_precision’)