This is a public Forum  publicRSS

Topic

    Saravanan Sekar
    How to call Controller/Libraries/Model from CPM?
    Topic posted April 16, 2018 by Saravanan SekarPro 
    107 Views, 8 Comments
    Title:
    How to call Controller/Libraries/Model from CPM?
    Content:

    Hi All,

    I am trying to call Library files from CPM by following the http://cxdeveloper.com/article/cpms-custom-process-management answer from cxdeveloper forum. 

    I am getting below error.

    Object Event Handler Inc_Update\Inc_Update does not define class Inc_Update!

    Here Inc_Update is my file/class name.

     

    Please help me with this approach. Also I am trying to call the Controller from CPM, but I am not sure the syntax. Please share that.

     

    Thanks in advance.

    ~ S.Saravanan

    Version:
    18 A

    Answer

     

    • Suresh Thirukoti

      Sarvanan - Can you paste the code here removing any unwarranted info..

      ~Suresh

    • Saravanan Sekar

      Hi Suresh,

      Please find the attached codes.zip file.

      Codes.zip (2KB)
    • Suresh Thirukoti

      Saravan - I think you missed this line in CPM

      use \Custom\Libraries\CPM\v1 as CPMHandler;

    • Suresh Thirukoti

      For your case, its "use \Custom\Libraries\CPM\V3 as CPMHandler;"

    • Saravanan Sekar

      Suresh - I have added the line of code as per your suggestion, but still am getting the same error.

       

      Object Event Handler Inc_Update\Inc_Update does not define class Inc_Update!

      Here Inc_Update is my file/class name.

    • Suresh Thirukoti

      can u try my way.......

      <?
      /*
      * CPMObjectEventHandler: XXXXXXXX
      * Package: RN
      * Objects: Incident
      * Actions: Create,Update
      * Version: 1.2
      * Purpose:
      */

      use \RightNow\Connect\v1_2 as RNCPHP;
      use \RightNow\CPM\v1 as RNCPM;

      class xxxxx implements RNCPM\ObjectEventHandler {
         
        public static function apply($run_mode, $action, $obj, $n_cycles) {     
          require_once("cp/customer/development/libraries/xxxx.php"); 
       
        }
      }

      In the library file

      <?
      // $run_mode, $action, $obj, $n_cycles

      use \RightNow\Connect\v1_2 as RNCPHP;

         $o_id = $obj->ID;
        ..............etc

      ~Suresh
       

    • Saravanan Sekar

      Hi Suresh,

      I tried as you mentioned, The library file is called successfully.

      Now am getting the below error (error in library file)

      ---------------------------
      Test Error
      ---------------------------
      Fatal PHP error on line 13 of /cgi-bin/mysite.cfg/scripts/cp/customer/development/libraries/CPM/V3/Inc_update.php:
      syntax error, unexpected '$incident' (T_VARIABLE), expecting function (T_FUNCTION)
      ---------------------------
      OK
      ---------------------------

       

      After I have added the below function line in library file, error is not coming.

       static function UpdateInc($runMode, $action, $incident, $cycle)
      {
      $incident=RNCPHP\Incident::fetch(946);
      $incident->subject="Lib Called";
      $incident->save();
      }

       

      Please let me know how to call this library function.

       

      Thanks,

      ~ S.Saravanan

    • Geetha Amrutha

      Hi Saravanan,

      To call a static function from libraries file in CPM, you can refer the below code -

      .......
      const DEV_MODE = true;

      define('APPPATH', DEV_MODE ? __DIR__ . "/scripts/cp/customer/development/" :  __DIR__ . "/scripts/cp/generated/production/optimized/");

      require_once APPPATH . "libraries/CPM/V3/Inc_update.php";

      use \RightNow\CPM\v1 as RNCPM;

      class xxxxx implements RNCPM\ObjectEventHandler
      {
          public static function apply($runMode, $action, $incident, $cycles)
          {
              CPM\V3\Inc_update::UpdateInc($runMode, $action, $incident, $cycles);
          }
      }

      ......

      Hope this helps.

      Thanks,
      Geetha