For example: whenever the user select any value the fields: From, To, Category then I need to run script that will calculate the Hope Price. So what java method to be used?
One more question: and how I can know the row number of the changed value of the child table? For example, I need to know if the changed value was in row 1 or row 2 of the field âFromâ?
Hello;
Thank you for the kindly reply.
I checked the link and it is talking about triggering the event in case of selecting (changing) certain field in the child table.
My question is: How to trigger the event in case of changing any field in the table?
I did not find answer in the link.
And I did not find a way to know if the changed value was in row # 1 or # 2 or # 3?
Regards
Bilal
Of course it was there. Let me copy and paste from the second post:
frappe.ui.form.on("Sales Order Item", "rate", function(frm, cdt, cdn) { // notice the presence of cdt and cdn
// that means that child doctype and child docname are passed to function and hence you can know what
// row was modified and triggered
var item = locals[cdt][cdn]; // this is where the magic happens
// locals is a global array that contains all the local documents opened by the user
// item is the row that the user is working with
// to what you need to do and update it back
var result = a + b + c;
item.result_field = result; // remember to refresh the field to see the changes in the UI
});
item.result_field = result; // remember to refresh the field to see the changes in the UI
});
How I can do refresh for field in the child table?
Why I need it? Because really I used the above script and the value appears in the field of the child table (and at the right position) just after adding the next row or doing save. So I am assuming maybe I have to refresh the field.
I tried the below script and until now it is not refreshing:
frm.refresh_field(âselected_categoryâ); // selected category is the field in the child table that need to be refreshed.
The thing that let me think that the problem is refresh is:
When I do save, the updated value appears. So for sure it is refresh, but I am surprised why I am not able to refresh using frm.refresh
Below is the script that I am running and the snap shot for the child table:
You need to refresh the childtable using the fieldname give to the same. So, if your childtable is called items then you would refresh it as follows refresh_field("items").
Also, you can leave it to the framework the refresh by using this function to set the value: frappe.model.set_value(cdt, cdn, "child_fieldname", value); inside the function definition so that is has access to cdt & cdn
This worked with me. And I would to add something: that this method was able to change the field value in the row that the change happened and it did not change all the rows and this is the required
Also other method worked which is: cur_form.refresh().
Also refresh_field(''childtable") worked fine, but I have to place the name of the table in the parent document that is directed to the child doctype. For example, if the table name in the parent document is âhopsâ and the child doctype is âtaxi hopsâ then I have to place the âhopsâ name.
The one that did not work with me is the refresh_field(âchild_fieldnameâ), this did not work with me.
Regards
Bilal