Child table name in database

I will try it and come back for you, if it is working it will be amazing.
By the way, it will be required to do refresh from the JS application to be shown at the user screen?
Regards
Bilal

frappe.ui.form.on("Expense Claim",{
	test: function(frm)
	{
		frappe.call({
		method: "erpnext.api.change_child",
		args: {parent_id: cur_frm.doc.name },
		callback: function(r)
			{
				location.reload(); 
			}
		});
	}
});

OK thank you, I am going to test.
But about the “parent”: parent_id: the document will be new (and not saved yet), so still no parent_id is existed. What should I pass in this case?

Regards
Bilal

I did some tests and I reached for the following:
If the document is saved (so its name determined, and the parent_id is determined), then it is working fine.
The problem if the document is still not saved (so its name is still not determined and the parent_id is not determined).
I tried to do cur_frm.save() but the problem that I am not able to capture the updated name (because it is saved in the database but still the cur_frm.name contains the old name (before saving).
I think my problem will be resolved if I can refresh the forms values after I do save … but how?

button_leaved_employees: function(frm) {
if (frm.doc.financial_year){
// cur_frm.save();
if (frm.doc.__islocal){
cur_frm.save();
}
frappe.call({
method: “erpnext.hr.doctype.r7_yearly_declaration_for_employees_that_leaved.r7_yearly_declaration_for_employees_that_leaved.get_leaved_employees”,
args: {
parent_id: cur_frm.doc.name,
financial_year: cur_frm.doc.financial_year
},
callback: function(r) {
// cur_frm.set_value(“registration_no_nssf”, r.message);
location.reload();
}
});
}
}

Regards
Bilal

Hello;

Appreciate if someone can help me by telling me how (if possible) to retrieve the forms parameters after using cur_form.save(), because I need to get the name of the saved form so I can use it in the remaining script.

Regards
Bilal

I’ll admit this is a stab in the dark, but did you try cur_frm.name or cur_frm.doc.name?

Yes of course I tried it as u can see in the above script that I posted it.
it gives the name of the form before running the save method, and that is why I am asking I need to retrieve the values of the form after saving because I need to get the form name (because the form gets name after first saving) and I need to know this name and the cur_frm.doc.name still contains the old name (the initial name of the form that is given for it before saving it as a first save).

Hopefully I was able to explain.
Regards
Bilal

I attached the following images which explain what is the situation:
The first image is showing how the form still does not have name as it is not saved yet and in this situation, the cur_frm.doc.name is returning the initial name which is New R7 Yearly Declaration For Employees That Leaved 1 (or New R7 Yearly Declaration For Employees That Leaved 2 or New R7 Yearly Declaration For Employees That Leaved 3, depending on the documents quantity).

The second image is showing the document after first save and how its name is changed and the name became the generated name from the system. But if I executed cur_frm.save() in case the document has not been saved before (because I need to name the document, so I can know the parent document name, so I can insert the needed fields in the child document name), then the cur_frm.doc.name is giving the initial name which is shown in the first image, it is still contains the name that was loaded when the trigger is happened and the java script file called.

Before the firs saving:

After the first saving:

Regards
Bilal

I was following this thread because (I now realize) I’m having the same problem. I apologize for being glib, should have considered the question more. Since I’m flailing at at this myself, consider these suggestions suspect:

I think the solution starts in correctly implementing _islocal. Here’s where I am getting that idea from. That should probably exist in some kind of if statement.

I think the next step is to use the frappe.meta class. I’m browsing these search results with some hope but not an obvious implementation.

Once you/we can get the record’s name, then you can proceed with populating the table.

@revant_one - I think this may be the issue I was describing in our thread.

@tmatteson
Why you think that meta class is going to give information other than what cur_frm.doc.name is going to return?

Regards
Bilal

A fair point. I’m guessing. What about this?

refresh_field("target_child_table");
frm.layout.refresh_sections();

This code is correctly populating on mine. I’m triggering it on a validate step. ddf_list_values is a dictionary.

function populate_details_table(ddf_list_values) {
 		cur_frm.clear_table("detail_table");
		for(i in ddf_list_values) {
			var c = cur_frm.add_child("detail_table");
			c.process_animal_item_detail = i;
			c.process_animal_qty = ddf_list_values[i];
			c.process_animal_uom = cur_frm.doc.process_default_uom;
			c.process_animal_date = cur_frm.doc.processing_date;
			c.process_animal_link = cur_frm.doc.animal;
		};
	refresh_field("detail_table");
	cur_frm.layout.refresh_sections();

Credit to @gvrvnk at MN Technique who promptly answered me as a paid support request, private channel.

I encountered a situation where I needed to move child record entries from one parent to another. We implemented a doctype called Item Categories (parent) which is composed of a list of different Item Classifications (Child Table). Unfortunately, since the users repeatedly renamed and created new categories for existing classifications, they had to encode, edit, delete the classifications in the child table over and over again. They requested to have this automated (to make their lives easier).

And here’s the python snippet that we came up with to insert the “Classifications” into the child table (Note: This was done in v7):

count = int(frappe.db.sql("""SELECT count(name) from `tabCategory Classes` where parent = %s""", category)[0][0]) + 1
				now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
				user = frappe.get_user().name
				frappe.db.sql("""INSERT INTO `tabCategory Classes` (name, creation, modified, modified_by, owner,
					docstatus, parent, parentfield, parenttype, idx, classification) VALUES
					(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
					(classification, now, now, user, user, 0, category, "classifications", "Item Category", count, classification))
			frappe.db.commit()

@bghayad

This function may also help:
tn = frappe.model.make_new_doc_and_get_name("Project")

I tried it and it did not work. Actually it creates new document and its name the same name that is given for the document before save. If u need the document name, then u need its name after save.
The problem after save that we are not able to get the updated name.

Regards
Bilal