[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

16 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.