1 Reply Latest reply on Apr 29, 2008 2:41 PM by (shane_mosier)

    converting numbers to text in a trigger

      I have created a custom form which inserts a record and sends an e-mail using the developer Toolbox "send e-mail to recipients from a records set ". Most of the form elements are drop-down boxes which return a numeric value. My problem is that when I come to sending the e-mail I want to send human readable information rather than just numeric values.

      I think I need to create a trigger which will take the insert transactions fields and select equivalent values to my drop-down boxes. it will then update the transaction fields with the text versions of the database record. this should alow me to email a text version of the email.

      Here is the trigger

      function Trigger_Custom_translate_advert_for_email(&$tNG) {
      $query = "SELECT *
      FROM
      tire_quality
      WHERE
      tire_quality.unique_id = 1";
      // THE QUERY HAS BEEN REDUCED FOR SIMPLICITY

      $select_result = $tNG->connection->execute($query);

      //HOW DO I RETRIEVE THE THE DATA FROM THE QUERY

      $tNG->addColumn("tire_quality_translated","STRING_TYPE","VALUE",$newValue);
      //I AM CREATING A NEW TRANSACTION FIELD TO PLACE THE TRANSLATED VALUE INTO

      if(!$select_result) {
      $updateError = new tNG_error("Error setting the initial message ID",array(),array());
      return $updateError;
      } else {
      return NULL;
      }
      }

      Does my strategy seem correct to you?
        • 1. Re: converting numbers to text in a trigger
          Level 1
          Chris,

          Your strategy seems fine. I don't think there is any reason to do a database query though? Unless I am missing something.

          I think you can just do a custom trigger set to execute AFTER the Insert transaction, but before the Email trigger. Make sure the transaction order of execution is correct so that the values are changed in the Custom Trigger AFTER the Insert transaction, but before the Email trigger.

          Something like this should work(lets say you use a numeric value for colors that you want to swap for the email):

          function Trigger_Custom_Swap_Colors(&$tNG) {

          // Get the submitted data from the form
          $color = $tNG->getColumnValue("color");

          // Conditional if statement to change number to color
          if($color == 1) { $color = 'Red'; }
          elseif($color == 2) { $color = 'Blue'; }
          else { $color = 'undefined'; }

          // Set the column value for the ADDT transaction variable
          $tNG->setColumnValue("color", $color);

          }

          So in short, all you do is grab the data from the form using getColumnValue, change the data to what you want the email to show, and then use setColumnValue to change the ADDT column value. Then when you email is sent it should use the modified column values.

          Hope this helps,

          Shane