Hello, I am trying to add row to table in doctype dynamically using add_child method but no success.i am stuck in this task since day.can anyone help on this issue on how to add row to table dynamically based on data from another doctype.any help will be appreciated.
@max_morais_dmm I m trying to add first one row after that as per doc data more row should be add
frappe.ui.form.on(âEmployee Timesheetâ, {
onload: function(frm) {
frappe.call({
âmethodâ: âattendance.attendance.doctype.employee_timesheet.employee_timesheet.get_employeesâ,
callback:function(r){
console.log(r.message);
frappe.msgprint("Javascript message "+r.message[0]);
var new_row = frm.add_child(âTimesheet child tableâ);
new_row.timesheet = âABCâ;
}
});
refresh_field(âTimesheet child tableâ)
}
});
@Hardik_Mehta, You need pass in âfrm.add_childâ the name of the field, and âTimesheet child tableâ dont sounds like a valid fieldname, usually itâs in lower case and with â_â underscores (eg: timesheet_details)
Check the right name of the field, in âCustomize Formâ or in the doctype âTimesheetâ
@Hardik_Mehta, the fieldname is the value that should be passed!
For example, the âSales Invoiceâ doctype, It already have 4 sub-tables, (âitemsâ â âSales Invoice Itemâ, âtaxesâ â âSales Taxes and Chargesâ, âpaymentsâ â âSales Invoice Paymentâ, âsales_teamâ â âSales Teamâ)
So, if you need add a new product in the invoice, the sub-table is âSales Invoice Itemâ, but in the body of âSales Invoiceâ itâs named âitemsâ, so, you will need the given script;
var child = cur_frm.add_child("items");
frappe.model.set_value(child.doctype, child.name, "item_code", "My Item Code")
cur_frm.refresh_field("items")
The child is in the âitemsâ shortcut, but is stored into âSales Invoice Itemâ!
Got me?
@max_morais_dmm thank you so much for your help.can u please help me on how to add data to child table automatically when data in some other doctype get saved.
Hey ,
How would you iterate through this list to see if the item is already present?
i searched a few options but cant exactly get how would you reference the child table to search for duplicate entries.
Any help is appreciated âŚ
Thanks.
@Taher_Khalil easy way is
var items_qty = {};
frm.doc.items.forEach(function(row){
if (!items_qty[row.item_code]) {
items_qty[row.item_code] = 1
} else {
items_qty[row.item_code] += 1
}
});
@max_morais_dmm
Thanks a lot ,
everything works but add_child function directly adds a child and value from the second row as first row is present by default.
Is there an inbuilt function like remove_child which i can set on_load to give me a empty table to begin with?
Thanks
@Taher_Khalil you can verify if the row exists and call frappe.remove_from_locals(doctype, docname)
But after that you need to reload the table with frm.refresh_field("table")
@max_morais_dmm
when i am doing frappe.remove_from_locals("items", "item_code")
then
frm,refresh_field("items")
in onload:function in sales_invoice.js âŚits not working.
what am i doing wrong?
Also is there any documentation or a cheat sheet highlighting all the inbuilt frappe functions like add_fetch, add_child and similar?
Thanks a ton for quick and helpful replies till now - youâre awesome
@Taher_Khalil, the issue, is the event, you could not do that on onload
event, cause it dont work, as the name of the event says, it is handled âwhen the form loadsâ, you need to pick the properly event, based on the user workflow, my sugestiong is make use of âvalidateâ
@max_morais_dmm , its doesnât seem to be working.
i just want the table to be blank at the beginning as soon as the the entire form loads like so
but where ever i put the code(tried a few places to declare on different workflows ) the table always comes with the first row and that results in the above situation.
kinda stuck
any help please
try this in onload
:
if(frm.doc.__islocal)
frappe.model.clear_table(frm.doc, "items");
@JoEz
it worked i changed it to cur_frm.doc
and it worked like a charm!
Thanks a tonâŚ
Also is there any documentation or a cheat sheet highlighting all the inbuilt frappe functions like these?
Hello @max_morais_dmm
I created web form for the subscription plan doctype. I want the user not click on the ADD ROW button under the Plans Table. Also the data I am trying to send to the table is not getting entered. Is this the problem with ADD ROW Button or the the problem with my URL Format.Please look at the following screenshots.
Thank You.
I want that add row button to be auto clicked and only one row should be added.
Please help me. Thanks in Advance
I want the button ADD ROW to be auto clicked when I load my web form. I am not able to enter the data unless the button is clicked. Some One help me