ERPNext Conference 2019* ERPNext.com Blog

[Tutorial] set_df_property for child table fields?


#1

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


How to add different values for each select dropdown options for different rows of a table
Hiding some fields in doctype based on User
#2

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”);


#3

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

Regards


#4

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


#5

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”);


#6

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.


Hide field using python
#7

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~


#8

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


#9

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