[Tutorial] set_df_property for child table fields?

How to set property of field in child table?

Ans: We can set property of doc fields using following syntax.

cur_frm.set_df_property(FIELDNAME, Property, Value);

e.g.

cur_frm.set_df_property("cheque_no", "reqd", doc.voucher_type=="Bank Entry");

We can also set property of fields in child table, which is the main reason for this post.
Syntax:

var df = frappe.meta.get_docfield("TABLE NAME","FIELDNAME", cur_frm.doc.name);
df.read_only = 1;

e.g.

var df = frappe.meta.get_docfield("Employer Project Details","company_name", cur_frm.doc.name);
df.options = ["Tech M", "Wipro", "TCS"];

Using above code, I have generated dynamic drop-down in child table field of Select type.

Reference:
http://sbkolate.blogspot.in

Thanks,
Sambhaji

18 Likes

Hi @kolate_sambhaji,

How can i change currency in child table as following image?

before it worked
cur_frm.set_df_property(“field_name”,“default”, “MMK”);refresh_field(“field_name”);

2 Likes

I think if you choose currency as type fetch it automatiqually.

Regards

1 Like

@magic-overflow
To change doc field use following script.

cur_frm.set_df_property(“total”, “fieldtype”, “Currency”);

also for table files use script
var df = frappe.meta.get_docfield(“Table Doctype Name”,“FIELDNAME”, cur_frm.doc.name);
df. fieldtype = “Currency”;

If you want to change precision, then from system setting you can change precision.

1 Like

Thanks @kolate_sambhaji. Your code is to change field type.

How can I change default currency?
Ex: total_claimed_amount, field type is Currency and USD as default. I want to change it depend on currency I choose.
Value $ 800, if you choose currency MMK, it will change to MMK 800.

before it worked
cur_frm.set_df_property(“total_claimed_amount”,“default”, “MMK”);
refresh_field(“field_name”);

1 Like

yes, in Sales Order has multi currency which the currency in the table change based on Currency selection automatically.

In my case, I try to customize Expense Claim to have multi currency.

Hi @kolate_sambhaji,

I did what you said, finally i figure out there is something you mentioned wrongly,

frappe.meta.get_docfield(“TABLE Doctype NAME”,“FIELDNAME”, cur_frm.doc.name);

Shouldn’t be TABLE Doctype NAME => LINK DOCTYPE NAME (Table option link name) , i tried the code which make me always hit error if i include Table Name… work fine when i put Link Doctype Name~

3 Likes

Thanks for providing the information, but how can I push different option values in different rows.

@Deep Did you figure out how to push different option values in different rows? I am also trying it out.

Here me too. Do you have any updates?

How can I make a child table field mandatory based on value in parent table field?

frm.fields_dict[‘items’].grid.update_docfield_property(‘qty’,‘read_only’,1)

6 Likes

This solution also not sufficient, i used it but did not able to solve my problem it works but for the current row, after save and refresh all the options will be cleared,
We can use stander property setter to achieve this
Just loop through the child table record and add following code.

cur_frm.set_df_property("child_table_field_name","options",["A","B","C","D"],current_form_name"field_name_of_chils_table","name_of_child_table_row")

This also have some drawback but works in my case.