Neither of those worked, any idea’s ?
Is it problem that nothing in my Child Table is a record in the database? I mean that the user manipulates the data and after that I update DocType records when user click save btn.
UPDATED WITH THE SOLUTION based on @rmehta comment :
@kickapoo Hi would you mind sharing the complete script. I tried to replicate your code since I need it for the Payment Entry Reference. I need to remove the rows that I don’t want to create a payment Entry for. this is the code frappe.ui.form.on("Payment Entry", "del_iv", function(frm, cdt, cdn) { frm.doc.references.splice(frm.doc.references[del_all], 0) frm.refresh_field('references') });
But I get this error in console ReferenceError: del_all is not defined
Where del_iv is the button in the parent that triggers and del_all is the check which I want to tick and the ones that are ticked, must remain the rest of the rows must be removed. Appreciate your help.
Your error message state that ‘del_all’ variable, where I assume is your index variable, is not defined. You have to define which ‘index’ you want to delete. Also, you have to think that `frm.doc.references[del_all]’ is a single DocType Instance of Referenses, and del_all is a integer index.
@kickapoo Thanks for your explanation, I have found another way to remove the rows.
below the reference to the thread in case you want to remove multiple rows based on some criteria inside the child table.
for the Payment Entry doctype it is a bit more complicated because the server side scripts running on refresh for the references so I had to add some script on the server side.
On top of that I added a validate SUM on the client side for the field paid_amount so the user does not need to calculate the paid amount.
Python Server
def clear_invoices(self):
self.set("references", self.get("references", {"del_all": ["not in", [0, None, ""]]}))
frappe.db.sql("""delete from `tabPayment Entry Reference`
where parent = %s and del_all = 0""", self.name)
if not frm.doc.references use an empty array [] . This is javascript “hack” for the code not give a errors in empty case.
function(i, d) : index, whatever object in the loop of frm.doc.references. In this case is named d from doctype and is the same as frm.doc.references[i]
So we can overcome this problem by having if statement to check if frm.doc.references if null or not. I have a question here: if there is no any document, what the returned value of frm.doc.references? Is it 0 or or false or null?
So each d is a document of the doctype, right?
Regards
Bilal