My case is I have custom button in a form which take values from fields and using frappe.call send it to server side which then send it to a REST POST request to create a document on other site.
The problem is there are empty field in the form. And the frappe.call seems not sending the empty key:value to the server side, hence generating fail in the requests.
If I fill-in or don’t include the empty fields, the script run sucessfully and post a document.
There is no default values. The value should be the same as in the form (collected by the button).
Now I use this to temporary assisgn value to the frappe.call fieldname args.
In the article, the examples saying the dict is empty. In my case the value for a key is empty. And this key is not passed to py. Hence the failure.
If I exclude the empty fields, the passing and requests are successful.
How is this if condition work?
There are keys that are not passed from js to py so py doesn’t know if the keys exist.
For example in the args of frappe.call
In my experience there are 2 scenarios to tackle in this context, 1. Empty field, 2. Field really exists or not. The 2nd problem can be solved easily by looping through the keys but 1st problem is different which is where you are stuck with.
As for the solutions, i have use this package validator · PyPI in a while now. It is much easier to handle complex validation scenario and easier to understand.
May be you can try it out too, i hope this help. Thanks.