Re: [Moonworks] Automatically add users name
Hi Moonworks,
You can look up the "fullname" of the user who created or last updated a record. Here's how...
Let's say you're working with a Product detail page. You'd already have this code in your page:
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$productsRecord = @$productsRecords[0]; // get first record
// show error message if no matching record is found
if (!$productsRecord) {
print "Record not found!";
exit;
}
After that code executes, you'll have access to the Product Record, and you can find the Account "num" of the user who created the Product in the "createdByUserNum" field. To look up that Account record, add this code immediately after the above code:
$accountNum = $productsRecord['createdByUserNum'];
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => "num = {$accountNum}",
'limit' => '1',
));
$accountsRecord = @$accountsRecords[0]; // get first record
Finally, you can display, for example, the "fullname" field from that Account record on the page:
Author: <?php echo $accountsRecord['fullname'] ?><br/>
I hope this helps! Please let us know if you have any questions or comments.
All the best,
Chris