I try to add bean to window object, this in the account detail view. In order to manipulate your data with javascript. I try the following. I try the following
function display()
{
$bean = json_encode($this->bean);
$javascript = <<<EOT
<script>
window.bean = {$bean};
</script>
EOT;
parent::display();
echo $javascript;
}
when I inspect window.bean
from the console I get undefined
, if instead of $bean
I use another value like some text
window.bean
shows the correct content
Interestingly if I try this code in an environment that is not suitecrm
$bean = json_encode(['name' => 'nami', 'email' => 'nami@domain.com']);
$javascript = <<<EOT
<script>
window.bean = {$bean};
</script>
EOT;
echo $javascript;
I get the expected result
<script>
window.bean = {"name":"nami","email":"nami@domain.com"};
</script>
Thanks for your comments