How to get the value of the field of a singleType Doctype on Salary Component Formula?

I’ve created a new singleType Doctype on a custom app along with few fields. I want to get the value of these field on Salary Component Formula for comparison. Is there any way to do that?

N.B: I’m using ERPNext V13

you can use below frappe api to fetch values from single doctypes:
frappe.db.get_single_value(doctype, fieldname)

1 Like

Does this method work inside formula? I’m bit confused.

yes you can use it in formula by storing in one variable

would you mind to write a simple example?

price = frappe.db.get_single_value(‘Stock Settings’, ‘update_existing_price_list_rate’)
if price == 1:
#your logic

Noted with thanks @Rehan_Ansari. I will try and update you back.

Not working bro. it says "Syntax error in formula or condition: invalid syntax (, line 1)

". @Rehan_Ansari

can you share the screenshot?

Here’s error message:

and my formula as follows:

hrdf_contribution = frappe.db.get_single_value("Contribution Settings", "enable_hrdf_contribution")


if hrdf_contribution=="1%":
    hrdf_contribution = 1
else:
    hrdf_contribution = 0.5
    
hrdf_contribution

not sure what’s wrong here as I’m new into this! please help @Rehan_Ansari !

what is the value stored in this field ‘enable_hrdf_contribution’.
because you are comparing in if hrdf_contribution==“1%”:.
if value stored in is 1% then is correct
or try with

if hrdf_contribution==“1”:

if you use enable_hrdf_contribution docfield as check type then try with this

hrdf_contribution = frappe.db.get_single_value("Contribution Settings", "enable_hrdf_contribution")

if hrdf_contribution==1:
    hrdf_contribution = 1
else:
    hrdf_contribution = 0.5

Yes it is 1% and the doctype is single type doctype and the field type is “Select”.

@Rehan_Ansari

@Rehan_Ansari Do you have any other recommendations? Any other possible way to get done? Thanks in advance!