Compare a field with list of values

Is there any way that I can compare the value of a field with a list of values in the select.
I want to use that expression in depends_on

@ruchin78 use the function in_list, same as

in_list(frappe.meta.get_docfield('Sales Taxes and Charges', 'charge_type').options.split('\n'), doc.charge)

Also, what is the way to use substr function in depends_on


eval:doc.my_string_field.indexOf('My Value')>-1
1 Like

Can you explore it, actually I want to use substr or substring like:

@ruchin78 you can use

1 Like

Great man, its done.
I appreciate if you can explain the reason for having === instead of ==

The same problem I am facing again. I have used it for a custom field in BOM Item.
Now I want that field should only be displayed if it satisfied the condition.


where item_group is also a custom field in the BOM Item.

The problem I am facing is, when I try to add a new row, it take the control to the home screen where all the modules are shown and on the console it gives an error:
Uncaught TypeError: Cannot read property ‘slice’ of undefined

@ruchin78, it is only a good pattern of JavaScript, “==” can be interpreted as “is the same of”, “===” can be interpreted as “have the same type, the same value, and the same length of”

In old versions of JavaScript “”, 0, false is interpreted as a falsity, and the JavaScript dont had a way for ask if the value as a instance of Boolean and have the false as value, so in the past, we would use,

var x = false;
if (typeof(x)=='Boolean' && x==false){}

The extra “=” has introduced to solve this.

@ruchin78, @System19 just for you understand about what I’m talking!

I apologize for not understanding, but I also appreciate if you can understand my problem.
I posted one issue, and you posted the solution for the same, I used it and found some issue then I again posted a query saying that I am facing such errors. Now where is the GAP, I don’t understand.

@ruchin78 I posted the solutions according you queries

Hi @max_morais_dmm.
I knew about the difference between == and === in Js but had no idea of its origins. So that was interesting. I usually just put === and hope for the best.
I try and copy all of the Js and Python solutions given on this forum into a local snippet app and then bodge/twist code from there. I am in no way a naturally gifted programmer. My neighbours complain about how I am constantly bashing my head against our shared wall. This keeps them awake apparently, well that and the cursing. Anyway am much better with Hardware. Mostly AV Delivery and Content Creation, Medical IT and Web Server Admin. Also handy with crayons. UI and Info-matic design.

1 Like

Thanks Max