We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36760
    • 136 Posts
    Thanks, I had completely forgotten about the PHP error logs when I was working through this! Luckily, changing the System Event priority to 1 has been working for the last week. If I find some time, I might do some more digging into why having it at 0 wasn't working.

    For anyone that may come across this thread in the future, this is the full code I eventually ended up going with. There might be something more efficient, but it works and doesn't slow down save times that I've noticed.

    <?php
    $contentId = $modx->resource->get('id');
    
    $tv_guideParentID_ID = 48;
    $tv_guideParentID = $modx->getObject('modTemplateVar', $tv_guideParentID_ID);
    $tv_guideParentID_val = $tv_guideParentID->getValue($contentId);
    
    $tv_guideChangeLog_ID = 37;
    $tv_guideChangeLog = $modx->getObject('modTemplateVar', $tv_guideChangeLog_ID);
    $tv_guideChangeLog_val = $tv_guideChangeLog->getValue($contentId);
    
    //$modx->log(modX::LOG_LEVEL_ERROR,'recentChangeDatePopulate ran');
    
    if($tv_guideChangeLog){
      if(!empty($tv_guideChangeLog_val)){
        $changeDate = $modx->runSnippet('getImageList',array(
          'docid' => $contentId,
          'tvname' => 'guideChangeLog',
          'tpl' => 'guideChangeLogDateNoFormatTpl',
          'reverse' => '1',
          'limit' => '1'
        ));
        //$modx->log(modX::LOG_LEVEL_ERROR,'changeDate: ' . $changeDate);
        $modx->resource->setTVValue('recentChangeDate', $changeDate);
      }elseif(!empty($tv_guideParentID_val)){
        //$modx->log(modX::LOG_LEVEL_ERROR,'guideParentID_val: ' . $tv_guideParentID_val);
        $changeDateParent = $modx->runSnippet('getImageList',array(
          'docid' => $tv_guideParentID_val,
          'tvname' => 'guideChangeLog',
          'tpl' => 'guideChangeLogDateNoFormatTpl',
          'reverse' => '1',
          'limit' => '1'
        ));
        //$modx->log(modX::LOG_LEVEL_ERROR,'changeDateParent: ' . $changeDateParent);
        $modx->resource->setTVValue('recentChangeDate', $changeDateParent);
      }else{
        $pubDate = $modx->resource->get('publishedon');
        //$modx->log(modX::LOG_LEVEL_ERROR,'pubDate (nolog noparentid): ' . $pubDate);
        $modx->resource->setTVValue('recentChangeDate', $pubDate);
      }
    } else {
      $pubDate = $modx->resource->get('publishedon');
      //$modx->log(modX::LOG_LEVEL_ERROR,'pubDate (nolog): ' . $pubDate);
      $modx->resource->setTVValue('recentChangeDate', $pubDate);
    }