PULLING DATA FROM AN ACCOUNT RECORD USING THE CREATEDBY FUNCTIONALITY BUILT INTO CMSB - Feb 1st, 2017


If you need to be able to pull information from the account record of the record owner (determined by the CreateBy field
of the record), there's a built in function that will save you a great deal of grief.

I had a number of product listing records that were created by subscribers, and wanted to give the subscribers the
option of filling in all of their contact information on each of the product listing records, or using their user
profile information to automatically populate those contact information fields in a viewer.

Ross Fairbairn, the consulting guru at Interactive Tools came to my rescue with a really easy fix.

His suggestion, "Just substitute:

$your_listing_tableRecord['createdBy.your_field'] instead of $your_listing_tableRecord['your_field'] (or use
$record['createdBy.your_field'] in your foreach loop)

This will use the built in createdBy function to do all the heavy lifting for you."

To offer the subscriber a choice, just include a checkbox in your listing table. and call it something like,
"use_profile_contact_information"

Then use an if statement to display the appropriate code.

<?php if($your_listing_tableRecord['use_profile_contact_information'] == '0'):?>
<?php if ($your_listing_tableRecord['your_field']) :?>
<b>Contact:</b> <?php echo $your_listing_tableRecord['your_field'] ?>
<?php endif ?>
<?php elseif ($your_listing_tableRecord['use_profile_contact_information']
==
'1'):?>
<?php if ($your_listing_tableRecord['createdBy.your_field']) :?>
<b>Contact:</b> <?php echo $your_listing_tableRecord['createdBy.your_field']
?>
<?php endif ?>

Ross added that, "createdBy fields load by default. You can disable them if you want in getRecords with:

'loadCreatedBy' => FALSE,

He went on to say that, "The only reason to disable them would be to save a on overhead when loading the page. In some
cases we've seen sites with 10,000+ users and loading the createdBy data can have a noticeable slowing effect on page
load times."




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service