I am trying to pull data from within the HTML file of a custom script report. The .html file works perfectly.
I have no problem pulling data on the script using my python file within the report folder. Same goes for the filters created using javascript.
The issue is when I try to call a specific function using Jinja from within the .html file. I understand that we are calling JavaScript functions defined in the JavaScript file.
Is there a way to call a whitelisted Python function directly from the print format html?
I tried using the frappe.call
callback javascript function, and I can trigger the Python function perfectly, I can even return the string to console and a frappe.msgprint, however I cannot get a simple string inserted into the HTML, instead I can only return [object Object]
, and am having issues in structuring how to access the direct contents of said object: {message:”String I Need”}
On the Script Report HTML file called when Printing:
<html>
<h1>Printed Report Title</h1>
{%= js_function_that_gets_string() %}
</html>
On the Script Report directory javascript file:
function js_function_that_gets_string() {
var string = '';
return string
}
On the init.py python file for my custom app:
@frappe.whitelist()
def my_python_function_with_business_logic(argument1):
# my awesome code using argument_1
return python_result
In hooks.py I added this line:
jenv = {
"methods": [
python_name_avail_to_jinja:my_python_function_with_business_logic
]
If I call the python function from Jinja, in a Custom Print Format, it works great, I get the exact contents of python_result
.
{{ python_name_avail_to_jinja() }}
When I try calling the Javascript function with a proper callback structure, I can get the message back, it displays perfectly well with a console.log()
But I cannot access the r.message
value properly, all I get in the HTML is
[object Object]
My specific problem or issue is to how to return this value with the javascript function call from the HTML Jinja. I thought of assigning the value perfectly well as a string, to a variable in the javascript function, and return this result when called from Jinja in the HTML, but this is not the expected behavior.