Assign Frappe call to variable

Hi all,

Currently I am trying to do a frappe call via javascript and assign it to a variable. This variable on javascript would be used to manipulate html file. Can anyone help me with this? Thanks! :slight_smile:

Javascript code

function searchThru() {
var ans = 0;
var ans = frappe.call({
method: “organizational_management.organizational_management.doctype.position.position.testing”,
callback: function(r) {
ans = msgprint(r.message);
}})
}

Python Code

@frappe.whitelist()
def testing():
return “test”

Edit
I was expecting “test” to appear instead “[object Object]” appeared.

Maybe your app is not restarted. Are you on development setup bench start ?

Hey @rmehta, I am on development setup and have migrate and did bench restart but to no avail.
Is this issue arising because html --> javascript --> python as compared to the usual javascript --> python ?

Perhaps you can point me to any relevant source code for me to dig around? :slight_smile:
Thank you!

Edit/ Updates:
I did a frappe.msgprint and the r.message comes out fine.
It is the assignment of varaible to ans that is not working fine.

I have also attempted. ans = r + ""; but to no avail

1 Like

Hi @rmehta would it be possible to point me to correct direction on this?
Thank you! :slight_smile:

Not able to figure why this would not work. Can you share your full repo?

I know this is “late” but I bumped into this exact same problem. I am able to obtain a string from my python function called with JS and frappe.call, but I cannot access the string itself when calling the JavaScript function, simply getting [object Object]

Will post something if I come up with a solution.