System Admin and Configuration

Get Involved. Join the Conversation.

Topic

    Scott Heidenreich
    Trigger Task Status change upon Incident SubmitAnswered
    Topic posted June 12, 2019 by Scott HeidenreichGold Medal: 3,500+ Points 
    60 Views, 17 Comments
    Title:
    Trigger Task Status change upon Incident Submit
    Summary:
    How do I change the status of a task, once an incident is submitted?
    Content:

    Hello,

    I have created a relationship between the task table (parent) and incident table (child)  This allows OPA to assign an existing task as a parent to the incident.  This is necessary because OPA won't map out to the task table and the incident table at the same time.

    The task is created by a customer contact, and I use the task ID as the object ID in the Contact Checkpoint table.  When the contact creates the task, it is set to "in progress" because it denotes an OPA interview that has been started but not submitted yet.  After the interview is submitted and creates the incident with the Task ID populated, thereby linking the incident to the task, I need to set the status of the task to "Completed", however, I don't see a way to trigger the business rules to do this.

    How do I get OSvC to set a task to "Completed" when the incident is submitted?

    Thank you,

    Scott

    Version:
    18D

    Best Comment

    Tushar Gupta

    Hi Scott, 

    I have corrected the CPM and attached the file. Now it should work. If you encounter any issue let me know.

    Thanks

    Comment

     

    • Sebastiaan Draaisma

      Hi Scott.

      A CPM would be able to do this. Let me know if you need assistance with this.

    • Scott Heidenreich

      Ok, I've watched some videos and read through the PHP API to understand how custom processes work.  Unfortunately, I'm not fluent in PHP.

       I need to build a custom process that will trigger when a specific type of new incident is created that has a specific value in a custom field, so I was going to create a business rule to call the event handler. This I know how to do.  However, building the event handler is where my difficulty lies.

      What I need it to do is when the eventhandler is called, read the parent Task ID stored in incident record that triggered the business rule.  The parent Task ID is in a custom field called incident.c$OPA2.OPA_TaskID, then find that task in the Task object and change the status to "Closed" and save the updated task record, then exit the process.

      This is the header I was using:

       

       <?
          /*
           * CPMObjectEventHandler: Close_Consultant_Task
           * Package: OracleServiceCloud
           * Objects: Incidents, Tasks
           * Actions: Update
           * Version: 1.1
           */
          // This object procedure binds to v1_1 of the Connect PHP API
          use \RightNow\Connect\v1_1 as RNCPHP;
          // This object procedure binds to the v1 interface of the process designer
          use \RightNow\CPM\v1 as RNCPM;

      But that is as far as I've gotten because I'm still foggy on the overall structure of the custom process php and the php commands.

       

      • Tushar Gupta

        Hi Scott,

        I have written this CPM. This would be able to update the Task Status

         

        <?php
        /*
        * CPMObjectEventHandler: Close_Consultant_Task
        * Package: OracleServiceCloud
        * Objects: Incident, Task
        * Actions: Update
        * Version: 1.2
        */
         
        // This object procedure binds to v1_2 of the Connect PHP API
        use \RightNow\Connect\v1_2 as RNCPHP;
         
        // This object procedure binds to the v1 interface of the process
        // designer
        use \RightNow\CPM\v1 as RNCPM;
         
        /**
        * An Object Event Handler must provide two classes:
        * - One with the same name as the CPMObjectEventHandler tag
        * above that implements the ObjectEventHandler interface.
        * - And one of the same name with a "_TestHarness" suffix
        * that implements the ObjectEventHandler_TestHarness interface.
        *
        * Each method must have an implementation.
        */
         
        class Close_Consultant_Task implements RNCPM\ObjectEventHandler {
        public static function apply( $run_mode, $action, $obj, $n_cycles ) {
        //Getting the Incident ID
        $incident_id = $obj->ID;
         
        if(strlen($incident_id) and is_numeric($incident_id)){
         
          $incident = RNCPHP\Incident::fetch($incident_id);
         
          //Get the Task ID from the Incident Custom Field
          $task_id = $incident->CustomFields->c->OPA_TaskID;   //Name of the Custom Field according to what you have in the Database
         
          if(strlen($task_id) and is_numeric($task_id)){
          //Fetch the Task with the Task ID
          $task=RNCPHP\Task::Fetch($task_id);
         
          //Update the current status
          if($task->StatusWithType->Status->ID){
            $task->StatusWithType->Status->ID = 18; // Completed Status ID
          }
         
          //Save the Task Object
          $task->save(RNCPHP\RNObject::SuppressAll);
          }
         
         
        return;
        } // apply()
         
         
         
        /*
        The Test Harness
        */
         
         
        class Close_Consultant_Task_TestHarness implements RNCPM\ObjectEventHandler_TestHarness {
         
        static $obj_invented = NULL;
         
        public static function setup() {
        // For this test, create a new
        // opportunity as expected.
        $obj = new RNCPHP\Incident;
        $obj->Name = "An Incident name";
        //$obj->Login = "a login";
         
        static::$obj_invented = $obj;
        return;
        }
         
        public static function fetchObject( $action, $object_type ) {
        // Return the object that we
        // want to test with.
        // You could also return an array of objects
        // to test more than one variation of an object.
        return(static::$obj_invented);
        }
         
        public static function validate( $action, $object ) {
        // Add one note.
        //print_r($object->Notes);
        //return(count($object->Notes) === 1);
        return 1;
        }
         
        public static function cleanup() {
        // Destroy every object invented
        // by this test.
        // Not necessary since in test
        // mode and nothing is committed,
        // but good practice if only to
        // document the side effects of
        // this test.
        //static::$obj_invented->destroy().static::$obj_invented = NULL;
        return;
        }
        }
    • Sebastiaan Draaisma

      I would normally be more than happy to assist you with this but my wife is in labor and I'm in the delivery room (I'm always connected) :-D
      I will be able to help you during the weekend with a working CPM, ready for use and detailed instructions (if you are able to wait)

    • Scott Heidenreich

      Oh my! Congratulations!  enjoy your new addition!

    • Scott Heidenreich

      Super fantastic!  I will try it out right away.  Thank you!!

    • Scott Heidenreich

      I've attached a screen shot of the data dictionary for this field.  It isn't listed in the custom field table, though.

    • Scott Heidenreich

      OPA2 is the package

      OPA_TaskID (Integer) is the field name and it is used as a foreign key to keep the Task ID for the parent task for the incident.

      But it shows on the screen as the Task Name when viewing the incident record in a workspace.

    • Scott Heidenreich

      I appreciate your help.  I put it into the process designer and tested it and it is throwing this error.

      • Tushar Gupta

        Hi Scott, 

        I have corrected the CPM and attached the file. Now it should work. If you encounter any issue let me know.

        Thanks

        • Scott Heidenreich

          Thank you, Tushar. The new code successfully passed the test button!

          Is there a reason for creating a new incident in the test harness but having the destroy function commented out?

          Also, is there a way to have the test harness load an actual record and then send the incident ID, task ID, and initial task status/final task status to the test results, but not save the changed task status to the database? This would allow me to verify that it is actually working before I deploy it.

          Your help is much appreciated!  I will be studying the code along with my Oracle University courses to make sure I understand what it is doing.

           

          • Tushar Gupta

            Actually, I had directly tested this without testing using the Test Harness.

            Basically, you should have all the methods i.e setup(), fetchObject(), Validate() and Cleanup() having the proper logics. 

            Yes, in the setup method instead of making the new Instance of the object, you can pass the Incident ID and fetch the Task ID in the Setup function and continue your testing.

            Below is the link of the article which would give you very good insights on CPM.

            http://cxdeveloper.com/article/cpms-101-introduction-custom-process-models  

    • Scott Heidenreich

      Thank you, I will read through the article carefully.  I deployed the custom process, created a business rule to call the custom process upon submittal of a new incident with the specific product for the incident, but it isn't changing the task status.

      I've confirmed the business rule is firing and operating properly, as the other steps of the rule are being executed successfully.

      • Tushar Gupta

        Hi Scott,

        It worked for me.

        It's probably because you are not getting the Task ID from the Custom Field which may be because of either No value is there in the Task Custom Field or the Task Custom Field name is different from the name which is written in the CPM. 

        You can test the code by a custom script and then use it in the CPM.

        Thanks

    • Scott Heidenreich

      Hi Tushar,

      I figured out what the trouble was.  The OPA_TaskID field was used by a relationship to the Task Table.  When I made a custom field that was a simple integer custom field then it worked perfectly.  However, that prevents the task from being associated with the incident when OPA submits the new incident to OSvC.

      I have been unable to figure out how to retrieve a parent object record using a relationship.  There is some info on this using a select command in ROQL, but I couldn't figure out how to fetch a parent's record from a child record.  In this case, the incident is the child and the task is the parent.

      Using:

       $task_id = $incident->CustomFields->c->opataskid1;

      and

      $task=RNCPHP\Task::Fetch($task_id);

      Allows me to fetch a task by ID, but there is no direct relationship identified in OSvC.

      The relationship field is Incident.OPA2$OPA_TaskID, this field holds the parents foreign key.