This is a public Forum  publicRSS

Topic

    Walter Kamp
    CPM test failure: "Undefined variable: object"Answered
    Topic posted December 5, 2017 by Walter KampApprentice 
    58 Views, 12 Comments
    Title:
    CPM test failure: "Undefined variable: object"
    Content:

    Since version Aug 2017, we cannot upload simple CPMs that worked fine before.
    When we test the CPM, we get error "Undefined variable: object", and we're not able to deploy it anymore. We have this now on 2 separate instances.

    I attached an almost empty CPM which can be used for reproducing the error.

    Version:
    Aug 2017
    File:
    test.php (853 Bytes)

    Best Answer

    Geetha Amrutha

    Hi Walter,

    We have encountered the same issue. Passing null in TestHarness used to work for old versions. I think this no longer works.

    The TestHarness fetchObject in your code is returning null. Try returning an existing/new record from the TestHarness. This must resolve your issue.

    Thanks,
    Geetha

    Answer

     

    • Suresh Thirukoti

      I think you are encountering recent upgrade to PHP whereas its much stricter in terms of Object access and instantiation....so in order to use an Object or its properties or methods, you need to use isset($object) like below

      if (isset($obj)) {}

      https://cx.rightnow.com/app/answers/detail/a_id/9256

      ~Suresh

    • Walter Kamp

      Hi Suresh,

      Thanks for your answer.
      I tried that already, but we still get the same error.

      In our sample PHP file we're not even using the $obj variable, so it really doesn't make sense to me.

      Also the error line mentioned in the error does not make sense. It always says line 24, but when I move that line to 25, the error still complains about 24.

      Regards,
      Walter

    • Saravanan S

      Hi Walter,

       

      Why don't try after changed the version to v1.3 instead of v1.0 in your code.

      If am not wrong, if we can upgrade directly to the aug 2017 from aug 2016 then Please let us know your previous service cloud version?

       

      Thanks,

      S.Saravanan

    • Suresh Thirukoti

      so I see that you are not passing any Object from test harness to the main class........is this working in the previous versions?

      ~Suresh

    • Chakravarthy Elchuri

      TestHarness is empty,  that is the reason u r getting error

      Try this

      <?
          /*
           * CPMObjectEventHandler: test
           * Package: OracleServiceCloud
           * Objects: Incident
           * Actions: Create
           * Purpose: test
           * Version: 1.0
           */
       
      use \RightNow\CPM\v1 as RNCPM;
      use \RightNow\Connect\v1_2 as RNCPHP;
          class test
                  implements RNCPM\ObjectEventHandler
          {
              public static function apply($run_mode, $action, $obj, $n_cycle)
              {
                   if($n_cycle !== 0) return;
                    return;
              } 
          }
          
          class test_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
          {
             static $incident = null;
          public static function setup()
          {
              $inc = RNCPHP\Incident::fetch(3724);//3724 is the existing incident id
              
              static::$incident = $inc;
              return;
          }
       
          public static function fetchObject($action, $object_type) {
              return array();
          }
       
          public static function validate($action, $contact) {
              return(True);
          }
       
          public static function cleanup() {
          }
          }
      ?>
    • Geetha Amrutha

      Hi Walter,

      We have encountered the same issue. Passing null in TestHarness used to work for old versions. I think this no longer works.

      The TestHarness fetchObject in your code is returning null. Try returning an existing/new record from the TestHarness. This must resolve your issue.

      Thanks,
      Geetha

    • Saravanan S

      Hi Walter,

       

      If we don't have anything in test harness then it will show only "Empty result" reply only.

      Give try by changing the version of your cpm.

       

         /*
           * CPMObjectEventHandler: test
           * Package: OracleServiceCloud
           * Objects: Incident
           * Actions: Create
           * Purpose: test
           * Version: 1.3
           */

       

       

      Please let us know, are you facing this issue with this dummy code (run directly without any changes)?

      Thanks,

      S.Saravanan

    • Walter Kamp

      Yes, works finally!
      Solution found in the fetchObject function... Although returning an array() worked fine in older CPMs, I had to change it to:
      public static function fetchObject($action, $object_type) {
              return RNCPHP\Incident::fetch(490729);//490729 can be any existing incident ID
          }

      Thanks for all the tips!

      Walter

    • Robert Surujbhan

      Hi Walter, a minor improvement you can make to your revised fetchObject function is the following (at least this way it's more generic for other objects you decide to use this CPM template for, other than Incidents, and it would be one less thing to change when you actually write out a proper test harness class).

      public static function fetchObject($action, $object_type) {
          return $object_type::fetch(1234);
      }
      

      Also, since the Connect v1.4 Common Object Model library is available now starting from August 2017, you can also update the "Version" value in the CPM's header/flower box to reflect 1.4 if you'd like.  This will bind the CPM to the newer version.

      * Version: 1.4
      
    • Saravanan S

      Hi Walter,

       

      If you can, please share your working code here similar to the sample code you attached initially.

       

      Thanks,

      S.Saravanan

    • Walter Kamp

      Sure, see attachment for a working version!

      Regards,

      Walter Kamp
      walter@wesquare.net

      test.php (1KB)
    • lara thomas

      Nice detail