This topic is locked
[SOLVED]

 How do you access the page object, inside the php snippet of a record?

7/22/2016 9:57:58 AM
PHPRunner General questions
P
PHPRunnerExplorer author

Hi,
In the Help Text, topic Adding PHP Code snippet, there's this sample line of code.
$record = $pageObject->getCurrentRecord();
, but when it's used in a PHP Code snippet, there's a run time error:
Call to a member function getCurrentRecord() on a non-object
, so it appears that $pageObject is not visible here, or maybe doesn't exist in any scope.
Even on some of the forum posts, that discuss this page object, it's not clear exactly how this array is populated.
I don't actually need this, am just experimenting with PHPRunner to become more familiar with it. What I'm trying to see in this case, is if it's possible to access the field values, outside of the field boxes. I'm just curious; this is not an actual issue.

Sergey Kornilov admin 7/22/2016

On Edit/View pages you can use the following in code snippet:

global $pageObject;

$record = $pageObject->getCurrentRecord();

print_r($record);
P
PHPRunnerExplorer author 7/22/2016

Of course. Of course. Forgot about letting php know the global scope.
Sorry about that, Serg. PHP is not my native language. Thanks.
Please mark this as answered.



On Edit/View pages you can use the following in code snippet:

global $pageObject;

$record = $pageObject->getCurrentRecord();

print_r($record);


Sergey Kornilov admin 7/22/2016

I have actually found that PHPRunner manual uses incomplete code sample, just like yours. We'll fix that, thanks for pointing.