Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Vanessa Abelardo Viana Beserra
    Set date and time field in a CPM
    Topic posted August 5, 2019 by Vanessa Abelardo Viana Beserra, tagged Connect PHP, Custom Process Models - CPMs 
    42 Views, 4 Comments
    Title:
    Set date and time field in a CPM
    Content:
    Hi,
    I have a custom process that makes a  logs information. I use the field DATA_FINAL (type: data and time) of object CO \ LOG_LUGGO. I just want to set a date in this field. I did a lot of tests, including setting a fixed date and still can't set it.
     
    My OSvC version is 19B. 
     
    Is there any configuration I should enable to use this? 
     
    Below is a script of how I am trying to set this field in PHP.
     
    Thanks for the help!
    Version:
    19B
    Code Snippet:

    Comment

     

    • Sebastiaan Draaisma

      Hi Vanessa.

      I'm afraid we would need to see the entire CPM (if possible) as the fault maybe located elsewhere in your script. Do you get any errors when testing your CPM?

      Would you be able to upload the CPM?

    • Vanessa Abelardo Viana Beserra

      Hi,

      No error message appears. And I can set the other fields of this object, I just can't set this date. Below is the complete code:

      <?php
       
      /**
       * CPMObjectEventHandler:CPM_LOG_LUGGO
       * Package: OracleServiceCloud
       * Objects: Incident
       * Actions: Create, Update
       * Version: 1.3
       */
       
      use RightNow\Connect\v1_3 as RNCPHP;
      use \RightNow\CPM\v1 as RNCPM;
       
      function createLogCPM($error, $cpm_name)
      {
          try
      {  
              $log_cpm = new RNCPHP\CO\LOG_LUGGO();
              $log_cpm->Error = $error;
              $log_cpm->CPM_NAME = $cpm_name;
              $log_cpm->save(RNCPHP\RNObject::SuppressAll);
          }
      catch (RNCPHP\ConnectAPIError $err)
      {
      CPM_LOG_LUGGO::addLog("Catch createLogCPM APIError ***: ".$err->getMessage(), '***');
      CPM_LOG_LUGGO::addLog("Catch createLogCPM APIError: ".$err->getMessage(), $obj->ID);
       
      }
      catch(Exception $err) 
      {
      CPM_LOG_LUGGO::addLog("Catch createLogCPM ***: ".$err->getMessage(), '***');
      CPM_LOG_LUGGO::addLog("Catch createLogCPM: ".$err->getMessage(), $obj->ID);
       
      }
          return;
      }
       
       
       require_once(get_cfg_var('doc_root').'/include/config/config.phph');
       
       $GLOBALS['log'] = true;
       
       class CPM_LOG_LUGGO implements RNCPM\ObjectEventHandler
      {
       
          public static function apply( $run_mode, $action, $obj, $n_cycles )
          {
       
       
          try 
      {
       
      echo "data_Criacao_teste".$obj->CreatedTime;
       
      if(isset($obj->prev->Disposition->ID))
      $sol_ant = $obj->prev->Disposition->ID;
      else
      $sol_ant = 0;
       
      echo "sol_ant".$sol_ant."\n";
       
       
      if(isset($obj->Disposition->ID))
      $sol_atual = $obj->Disposition->ID;
      else
      $sol_atual = 0;
       
       
       
       
      if(isset($obj->prev->Category->ID))
      $category_ant = $obj->prev->Category->ID;
      else
      $category_ant = 0;
       
      // Aqui eu pego a categoria atual
       
      if(isset($obj->Category->ID))
      $category_atual = $obj->Category->ID;
      else
      $category_atual = 0;
       
       
       
      if($sol_atual != $sol_ant || $category_atual!=$category_ant)
       
      {
       
      $log_cpm_luggo = new RNCPHP\CO\LOG_LUGGO();
       
      $log_cpm_luggo->ID_INCIDENTE = $obj->ID;
       
       
      if(isset($obj->Disposition->ID))
      $log_cpm_luggo->SOLUCAO = RNCPHP\ServiceDisposition::fetch($obj->Disposition->ID);
       
      if(isset($obj->Category->ID))
      $log_cpm_luggo->CATEGORIA = RNCPHP\ServiceCategory::fetch($obj->Category->ID);
       
      $log_cpm_luggo->STATUS =$obj->StatusWithType->Status->LookupName;
       
      $log_cpm_luggo->DATA_FINAL=time();
       
      echo "dataaaa".$obj->DATA_FINAL;
       
      $log_cpm_luggo->save(RNCPHP\RNObject::SuppressAll);
      $obj->save(RNCPHP\RNObject::SuppressAll);
      }
       
       
      }
       
       
      catch (Exception $e) {
          echo 'Exceção capturada: ',  $e->getMessage(), "\n";
      }
       
       
       
      return;
      }
       
       
       
      }
       
       
       
      Thanks!
      • Lakshay Bhalla

        Hi Vanessa Try changing this:

        $log_cpm_luggo->DATA_FINAL=time();

        to this:

        $log_cpm_luggo->DATA_FINAL = strtotime(date('l, F d y H:i:s'));

        It worked for me.

        Thanks

        - Lakshay

        • Robert Surujbhan

          Hi Vanessa, another option is this:

          $log_cpm_luggo->DATA_FINAL = strtotime("now");
          

          Also, if you always just need the current time, using the Object Designer, you can also easily set the Dynamic Default option on the DATA_FINAL field to "Current Time" and re-deploy the object - this way, you wouldn't have to set the value in your code.