I’ve run across an odd situation and it’s got me stumped…
I was trying to use CurrentUserInfo(‘Status’) in the Menu_Adding() event to ensure that menu options were being presented on an “as needed” basis, but then noticed that the menu wasn’t displaying correctly, so I added the following snippet:
To my surprise, the profile ID displayed correctly, but the Status value was wrong (it returns 1 but the DB holds 2).
I’m currently pulling the Status value with ExecuteScalar, so the menu is at least working correctly now, but I’d really like to know why CurrentUserInfo() is playing up.
Okay… some additional digging has uncovered the root of the problem.
CurrentUserInfo() was pulling data from Profile() (the global user profile object) rather than going to the DB record.
I had specified “Server” for saving search filters, even though I changed “Server” to “Client” and regenerated everything, the Profile field in the data record doesn’t get cleared out, so the old filter settings remain and CurrentUserInfo() continues to return irrelevant values.
Fortunately, I was able to apply a simple fix (see below) so the correct values are now returned …time will tell if the search filters are affected.
function CurrentUserInfo($fldname) {
global $Security, $UserTable;
$value = NULL;//Profile($fldname); <—just set $value = NULL to force a DB read
if ($value != NULL) {
return $value;
} elseif (isset($Security)) {
return $Security->currentUserInfo($fldname);
} elseif (Config(“USER_TABLE”) && !IsSysAdmin()) {
$info = NULL;
$filter = GetUserFilter(Config(“LOGIN_USERNAME_FIELD_NAME”), CurrentUserName());
if ($filter != “”) {
$sql = $UserTable->getSql($filter);
if (($rs = Conn($UserTable->Dbid)->execute($sql)) && !$rs->EOF) {
$row = $rs->fields;
$info = GetUserInfo($fldname, $row);
$rs->close();
}
}
return $info;
}
return NULL;
}
Thanks, Adam. I encountered this issue a few weeks ago. Sometimes CurrentUserInfo(“”) worked, and sometimes it didn’t work. I think your customization is right. CurrentUserInfo should always get the values from the related fields in “users” table, and not from the Profile field.
I appreciate that most v2020 users will upgrade to v2021, but this issue should be addressed as a final v2020 template update for those who still need to use that version and/or aren’t able to migrate projects immediately.