ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

How to get number of current row of child table

customization

#1

Hi everyone,
I have a usecase that is when i click link field of childtable i would like to display current row’s number for example

if i click INS/00006 i need to get one or zero as result.


#2

Are you referring to the Serial No. which is already a first column of the table? If no, please further elaborate, may be with some annotation.


#3

this is my custom script js ffile

frappe.ui.form.on("Team", "instructor", function(frm,cdt,cdn) {

			
			frappe.call({
					method: "ims.ims.doctype.fe_settings.fe_settings.get_employee_details",
					args: {
						"instructor_id": **current_instructor_id**,
					},
						async: false,
					callback: function(r) {
						if(r.message) {

								locals[cdt][cdn]['instructor_name'] =r.message[0]["instructor_name"];
								locals[cdt][cdn]['phone_number'] =r.message[0]["cell_number"];
								locals[cdt][cdn]['designation'] =r.message[0]["designation"];
								locals[cdt][cdn]['email'] =r.message[0]["company_email"];
								locals[cdt][cdn]['image'] =r.message[0]["image"];
								// refresh_field("team");
								refresh_field("instructor_name");
								refresh_field("phone_number");
								refresh_field("designation");
								refresh_field("email");
								refresh_field("image");
							}
					}
				});	

			
});

i would like to get the current instructor id as INS/00006
Thanks for replying fast


#4

try following script

frappe.ui.form.on('Table Doctype Name', {
	link_fieldname: function(frm,cdt, cdn){
		var row = locals[cdt][cdn]
		frappe.call({
			method: "ims.ims.doctype.fe_settings.fe_settings.get_employee_details",
			args: {"instructor_id": row.idx},
			async: false,
			callback: function(r) {
				//do your operations here
			}
		})
	}
})

#5

Hello;

Is there something like this?

var row = previous[cdt][cdn];

It is required to set and get the value of the previous row, and it is much more better if there is a method to access (set/get) any field value in any row in the child table, appreciate if to know the syntax of the code to reach it.

Regards
Bilal


#6

is it possible to set the value of a field of the current child table row ?

Basically i would like to set the default user warehouse for the current row of the sales order item.

if yes how ?

the below script updates all rows as per the each loop

frappe.ui.form.on('Sales Order', {
onload_post_render: function(frm, cdt, cdn)
	{
		frm.fields_dict.items.grid.wrapper.on('blur', 'input[data-fieldname="item_code"][data-doctype="Sales Order Item"]', function(e) {
		
		frappe.call({
			method: "frappe.client.get",
			args: {
				doctype: "User",
				filters: {"name": frappe.user.name} ,//user is current user here
				fieldname :["warehouse"]   
			},
			callback: function(r) {
					$.each(frm.doc.items || [], function(i, v) {
					frappe.model.set_value(v.doctype, v.name,"warehouse",r.message.warehouse)
				})
				frm.refresh_field('items');
		}
		});
				


});
}
});

#7

hi
hope this can help you

cur_frm.open_grid_row()


#8

Nopes. tried on console gives undefined.

OR may be i don’t know how to use it.

Could you please elaborate seeing my script how to place it instead of $.each ?


#9

Try something like this

frappe.ui.form.on('Sales Order', {
	onload: function(frm) {
		frappe.call({
			method: "frappe.client.get",
			args: {
				doctype: "User",
				filters: {"name": frappe.user.name} ,//user is current user here
				fieldname :["warehouse"]   
			},
			callback: function(r) {
				frm.set_value("set_warehouse", r.message.warehouse)
			}
		});
	}
});

If you’re not on v11 then use the $.each(frm.doc.items, …)


Logged in User wise default warehouse in Sales Order Item
#10

Thanks for your solution, it will work great in v11.

But at present i am not on v11.
Let me put more clarity on my requirement, i would like to set default warehouse only when new row / item is selected but user should be able to change it afterwards.

i tried using $.each(frm.doc.items, …) as mentioned above but it updates warehouse for all rows, which will eventually overwrite/update even those rows for which user wanted to change the warehouse.


#11

Try something like this then

frappe.ui.form.on('Sales Order', {
	items_add: function(frm, cdt, cdn) {
		frappe.call({
			method: "frappe.client.get",
			args: {
				doctype: "User",
				filters: {"name": frappe.user.name}, //user is current user here
				fieldname : "warehouse"   
			},
			callback: function(r) {
				frappe.model.set_value(cdt, cdn, "warehouse", r.message.warehouse)
			}
		});
	}
});

#12

Thanks for your kind help.

Tried.

But unable to set the value, it seems the erpnext function
erpnext.stock.get_item_details.get_item_details
is being called just after my call, which overrides the value.

It seems , the only option left is to override the function
erpnext.stock.get_item_details.get_item_details
through custom app.


#13

‘onload_post_render’: function(frm, cdt, cdn) {
var list = frm.doc.entry_dashboard_list;
frm.fields_dict.entry_dashboard_list.grid.wrapper.on(‘focus’, ‘input[data-fieldname=“new_entry”][data-doctype=“Entry Dashboard List”]’, function(e) {
var current_doc = $(’.data-row.editable-row’).parent().attr(“data-name”);
var d = locals[“Entry Dashboard List”][current_doc];

Here,
entry_dashboard_list - Child table name,
new_entry - child table field name
click on a any row in the new_entry(column name in a child table)field you can access that full row by d.field_name