This topic is locked

Get record value in code snippet on view page

10/1/2024 2:06:07 AM
PHPRunner General questions
H
headingwest author

I have a code snippet embedded on a view page and can't figure out how to get the record data.

The following returns an empty string:

$_SESSION["currentRecord"] = $values;
echo $_SESSION["currentRecord"]["vaultid"];

Thanks for any help.
Using version 10.91

mbintex 10/1/2024

Two solutions here:

  1. Have a virtual field in your SQL query like select '' as messagefield, put that on your view in Page Designer and have $value for View to your liking.


  2. Push the field values to a session variable and echo that. If your session variable is empty, you have not filled it with the record value in an event before.



C
cristi 10/1/2024

Sessions in php can be used as arrays.
Probably you are not defining your session in the correct event or you're not writing the code correctly - without some debug messages I can't tell.
You should define the session array in the view page "Process record values" event and it should work - it works in my case anyway - maybe vaultid is not a key in that array because it not written like that? - if you var_dump the $_SESSION["currentRecord"] array what do you see?

Admin 10/1/2024

You cannot directly access field values in the code snippet, code snippets are not events and run in their own context.

You can do however what @cristi suggests, use Process Record Values event to save $values array in a session variable and then access this array in your code snippet.