This is a public Forum  publicRSS

Topic

    Justin L
    CPM current incidentAnswered
    Topic posted December 31, 2017 by Justin LWhiz 
    104 Views, 9 Comments
    Title:
    CPM current incident
    Content:

    I've create a new CPM script and have everything working except when using as part of a Business Rule on an incident.

    How do i set the current incident->ID to a variable?
    $currentincidentid = Incident-->ID fails, as well as a bunch of other guesses...

    All the examples show creating an incident and capturing the result to a variable to get the incident id, but here it's already created.

    (Basically as incident flows through the business rules I want to capture the Incident ID, Org ID and Product, so that I can query other data to populate for reporting).

    Any help would be great

    Thanks

    Version:
    Feb 17

    Best Answer

    Suresh Thirukoti

    You have to paste CPM code after removing sensitive info...,...just FYI....do you have the following as your CPM apply method signature....if you are using different signature, try to use it...

    public static function apply( $run_mode, $action, $incident, $n_cycles )
      {

        if (isset($incident))

    {

    //there goes the manipulation or reading the object data

    }

    ~Suresh

    Answer

     

    • Suresh Thirukoti

      You have to paste CPM code after removing sensitive info...,...just FYI....do you have the following as your CPM apply method signature....if you are using different signature, try to use it...

      public static function apply( $run_mode, $action, $incident, $n_cycles )
        {

          if (isset($incident))

      {

      //there goes the manipulation or reading the object data

      }

      ~Suresh

    • Justin L

      Thanks Suresh, but I must still be doing something wrong in extraction the ID

      Maybe this is incorrect    $incidentid = $incident->Incident->ID;

      If I test the same code via File Manager, supplying the ID works fine.

      Justin

       
      class MinimalIncidentHandler implements RNCPM\ObjectEventHandler
      {
          /**
           * Apply CPM logic to object.
           */
          public static function apply($runMode, $action, $incident, $cycle)
          {
          if (isset($incident))
      {
      $incidentid = $incident->Incident->ID;
                     
      $incidentObj = RNCPHP\ROQL::queryObject("SELECT Incident FROM Incident WHERE Incident.ID = {$incidentid}")->next();
      $currentincident = $incidentObj->next();
      if ($currentincident) {
      $currentincident_org_id = $currentincident->Organization->ID;
      $currentincident_prod_id = $currentincident->Product->ID;
      }
       
      ....
    • Suresh Thirukoti

      Yes Justin, it looks like ID retrieval is wrong and also object is available for you in the CPM so you can manipulate it directly instead of ROQLing... try this

      class MinimalIncidentHandler implements RNCPM\ObjectEventHandler
      {
          /**
           * Apply CPM logic to object.
           */
          public static function apply($runMode, $action, $incident, $cycle)
          {
          if (isset($incident))
      {
      $incidentid = $incident->ID;
           
      $currentincident_org_id = $incident->Organization->ID;
      $currentincident_prod_id = $incident->Product->ID;
      }
      ~Suresh
    • Justin L

      Thanks for the fast reply but that failed also, I'm going to write CPM with new fields (nothing sensitive), that is populates the incident, id, product id and org id into those new custom field. Maybe that will help with my understanding.

      If there's any other feedback it would be appreciated.

      Justin

    • Suresh Thirukoti

      Can you paste the complete CPM code here so I or experts in the forum can have a look ....

      ~Suresh

    • Justin L

      Hi,

      Here is the code I'm testing, but still no luck picking up ID, any expert suggestions on what I'm doing wrong would be great.

      Thanks

      <?
      /*
       * CPMObjectEventHandler: test
       * Package: OracleServiceCloud
       * Objects: Incident
       * Actions: Create, Update
       * Purpose: test
       * Version: 1.4
       */

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

      class test
          implements RNCPM\ObjectEventHandler
      {
          public static function apply($run_mode, $action, $obj, $n_cycle)
          {
              if ($n_cycle !== 0) return;
              if (isset($incident)) {

                  $incidentnow = $incident;
                  $incidentidnow = $incidentnow->ID;
                  $incidentnow->CustomFields->c->cbo_test01 = "Test1";
                  $incidentnow->CustomFields->c->cbo_test02 = $incidentidnow;
                  $incidentnow->save();

              }
          }
      }

      class test_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
      {
          static $incident = null;

          public static function setup()
          {
              $inc = RNCPHP\Incident::fetch(13238);//13238 is the existing incident id

              static::$incident = $inc;
              return;
          }

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

          public static function validate($action, $incident)
          {
              return (True);
          }

          public static function cleanup()
          {
          }
      }

      ?>

    • Suresh Thirukoti
      In your apply () method, its mentioned $obj whereas you are referring $incident.... So change $obj to $incident ~Suresh
    • Justin L
      Using this as my framework, I can do everything I want with incidents. Just need to develop a true TestHarness.
       
      Thanks 
       
       
      <?
      /*
       * CPMObjectEventHandler: test
       * Package: OracleServiceCloud
       * Objects: Incident
       * Actions: Create, Update
       * Purpose: test
       * Version: 1.4
       */
      use \RightNow\CPM\v1 as RNCPM;
      use \RightNow\Connect\v1_4 as RNCPHP;
      class test
          implements RNCPM\ObjectEventHandler
      {
          public static function apply($run_mode, $action, $incident, $n_cycle)
          {
              if ($n_cycle !== 0) return;
              if (isset($incident)) {
                  $incidentnow = $incident;
                  $incidentidnow = $incidentnow->ID;
                  if ($incidentnow) {
      $currentincident_org_id = $incidentnow->Organization->ID;
      $currentincident_prod_id = $incidentnow->Product->ID;
      }            
              }
          }
      }
      class test_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
      {
          static $incident = null;
          public static function setup()
          {
              $inc = RNCPHP\Incident::fetch(13238);//13238 is the existing incident id
              static::$incident = $inc;
              return;
          }
          public static function fetchObject($action, $incident)
          {
              return $incident::fetch(13238);
          }
          public static function validate($action, $incident)
          {
              return (True);
          }
          public static function cleanup()
          {
          }
      }
      ?>
    • Suresh Thirukoti
      This part kindly update as follows and check
       
      class test_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
      {
          static $incident = null;
          public static function setup()
          {
              $inc = RNCPHP\Incident::fetch(13238);//13238 is the existing incident id
              static::$incident = $inc;
              return $inc;
          }
          public static function fetchObject($action, $incident)
          {
              return static::$incident;
          }