Using CurrentUserID() in Custom Files

mansour wrote:

We should start session at the beginning of custom file. Isn’t it?

Yes. That’s why you should not include the common files yourself and bypass PHPMaker code.As explained in the other topic (https://discourse.hkvstore.com/t/converting-v2020-custom-files-to-v2021/3731/1):

If you just need to return some result of an action (e.g. a value by > ExecuteScalar() > or a row by > ExecuteRow()> ), it is better and simpler to use > Route_Action > server event, then you can define your parameters in the route and get the value in your code by > $args[“xxx”] > or > Route(“xxx”)> .

If you use Route_Action server event, you may define route with parameter, you can also pass the patient ID as route parameter and there is no need to use cookie. Instead of echo, just write your result to the response by:
$response->getBody()->write($myResult); // Write to response body