How to get the record id of the current record that I'm viewing?

SuiteCRM 7.11.23

I was making a chart inside the detailsview account, Make a custom field, added a customCode to that field in the detailsviewdefs that points to a an Entrypoint inside an Iframe. Managed to display the chart from the entrypoint to the Account’s detail view.

My only problem is, how to I get the record ID of the current record that I’m viewing.
I was planning on putting that inside my sql query:

Help or any kind of tip would be much appreciated!

Maybe this approach could work for you

Thanks for the reply.

I have already read that and have already made the Iframe, not to mention render it to the Accounts detailview. My problem is how do I get the ID of the current record that I’m viewing because right now, I have to manually put the record’s ID in the sql query. And that is no good at all.

The post explains how to do that. Which step of that tutorial are you having trouble with?

I didn’t do any of the stuff because I used Studio for that. We have to do it via Coding.
I made an Iframe via the customCode attribute in the detailviewsdefs. Inside the Iframe is the entrypoint to render the chart.

I tried using ‘$this’ to access the current bean but it’s empty. Maybe because it’s inside an Iframe so it does not detect the current record bean? I don’t know and that is what I’m struggling right now…

You have to pass the variable through the URL into the iframe, as a GET variable.

You should just try the example as it is and get it working and then have a look at the files generated by Studio and get your code-only customizations from there. Studio is often the easiest way to figure things out, even if you don’t want to depend on it later for other strategic reasons.

1 Like

I did it. This is in the src of the Iframe:
http://suite/index.php?entryPoint=chartJS&account_id={$fields.id.value}

Pulled it in the sql query:
account_id = ‘{$_REQUEST[‘account_id’]}’

Cheerios!

Don’t forget to add in a bit of security sanitizing to avoid SQL injections into your entrypoint.

$account_id = DBManagerFactory::getInstance()->quote($_REQUEST['account_id']);
1 Like

This returns an empty string when I try to output it using ‘print_r’? I have not done any sanitizing yet as I am new to suiteCRM and in the phase of getting used to the system…

Edit: Forgot to change the backticks when I copied your code :confounded: