Francesca Shiekh

HowTo: Mass Update the Comment Log

Discussion created by Francesca Shiekh on Dec 26, 2019

Our Sales team had a need to mass-Update the Comments Log in our Leads Module.

 

As you may know you can't make that field massupdateable it even with vardef manipulations because the Comments Log is not really a field, it is a related module.

 

To achieve what we needed we defined a mass updateable text field comment_update_c in our Leads Module using Studio.

 

We then added an After Save Logic Hook to our LeadsLogic to copy the contents of that field to a Comments Log entry when the Lead is saved and clear the comment_update_c field.

  function update_log($bean,$event,$arguments) {
    if(!empty($bean->comment_update_c)) {
      $link = 'commentlog_link';
      if($bean->load_relationship($link)){
        //create the comment record
        $comment = BeanFactory::newBean('CommentLog');
        $comment->entry = $bean->comment_update_c;
        $comment->save();
        //link it to the bean
        $bean->$link->add($comment->id);
        $bean->comment_update_c = '';
        $bean->save();
        //no need to worry about recursion even if this is an after-save
        //the next time this logic hook fires the comment_update_c is empty
      }
    }
  }

 

The comment_update_c field is not included in any of the views - it is always empty - but is available in Mass Update.

 

This works for us, if you have a better solution please do share it!

 

Thank you,

FrancescaS

Outcomes