Use frappe.db.get_value within a Depends On doesn't work

I have setup some custom fields on the Item form - they are checkboxes which I want to then use to trigger fields to show or not on the Sales Order Item form.

So I have my Item setup with a custom field called soi_size which is a checkbox. I have that checkbox set to ticked (Yes).

And then on the Sales Order Item field I add Depends On:

eval:frappe.db.get_value("Item", row.item_code, "soi_size") = 'Yes'

But when I try to add a Sales Order Item line it closes immediately - is what I’m attempting not possible?

Is there any other way to do this? I have a lot of conditions to check when showing or hiding fields so this seems the most efficient and logical way to set it up - and it makes it easy to administer in future.

In depends on feild, you can only add javascript condition, server side functions does not work. Hence, first you have to fetch soi_size value in Sales Order Item table, then write depends_on value based on that field.

So I would need to write a custom script first to fetch the soi_size value then I could refer to it in the form Depends On statement?

Any tips on a starting point for the custom javascript?


I’m trying a custom script on Sales Order Item form thus:


But it doesn’t bring the SOI Size checkbox value through from the Item table to the Sales Order Item Form

Does this work with Check field types?

Check Not Found

Hi @nabinhait,

Still no success, I have setup exactly as described but the SOI Size check does not push through from Item to Sales Order Item:

Oh and to confirm I do have the Options set:

I think I’ll just have to give up on this one - not even your example works @nabinhait. Either something has changed in a later version or… :frowning:

Edit: OK to confirm even if you setup the field as Read Only you STILL need to add the custom script to draw the value through. Now to test if Check field type works…

Definitely doesn’t work with Item → Sales Order Item unless I’ve got something wrong:

I think the fieldname is item_code not item

Nope. I tried that and I tried both item_code.soi_size and item.soi_size in the Options for the Item and it still doesn’t work.

I tried new fields, different field types, nothing works - as I say it’s looking like you can’t do the fetch from Sales Order Item to Item?

Edit: Definitely not working no matter what combination of information I try. I’ll go back to setting up my very long Depends On logic - I hope there’s enough characters allowed in that field! :smiley:

While creating custom script, select DocType as “Sales Order”, instead of “Sales Order Item”. It should work.

And if you are writing custom script then don’t specify Options in the custom field created for “Sales Order Item” table.

Edit: OK I understand. So I’ve setup thus and it still doesn’t work. Any other ideas?

It should be cur_frm.add_fetch("item_code", "soi_print_process", "soi_print_process") in custom script