Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Marv Ferrer
    Connect PHP - Get ID of Current Incident/ObjectAnswered
    Topic posted July 21, 2016 by Marv FerrerSilver Trophy: 7,500+ Points 
    545 Views, 20 Comments
    Title:
    Connect PHP - Get ID of Current Incident/Object
    Content:

    I'm trying to grab some incident information and push them into an external form when an incident is saved/updated. And I'm trying to do so from the Process Designer.

    I can't seem to find in the documentation on how to get the ID of the incident/object that is currently being created/updated. 

    We need a more user-friendly developer documentation, in general! LOL

    Best Comment

    Anuj Behl

    If you don't find much in documentation, there's a blog post detailing how to write a first CPM which might help you.

    Comment

    • Barrilito van Dijk

      Hi Marv,

      See here the link for the documentation.

      In a cpm the object is defined by $obj (if you call it like public static function apply( $run_mode, $action, $obj, $n_cycles ) )

      From there on it is connect php code, see the documentation here.

      So if your object is an incident, the id will be.

      $inc_ID = $obj->ID;

      Regards.

       

       

    • Mark

      Hi Marv,

        Yes, agree about the docs. ;-)  Learning will be a lot of trial and error. :-(. Don't be afraid to post questions!  Sometimes the only documentation is in comment in the sample code. May not always work, but will often get you started.  Here are the params for apply():

      
      /*********************************************************************************
      *Parameter description and values for apply() function: *
      * $run_mode - determines if the script is running in production or in test mode *
      * values: RunModeLive or RunModeTestHarness *
      * $action - what type of CRUD event is happening *
      * values: ActionCreate, ActionUpdate, or ActionDestroy *
      * $object - the object being acted upon *
      * values: Incident, Answer, Contact, Organization or Opportunity *
      * $n_cycles - how many loops the script has entered *
      * values: 1..5 *
      *********************************************************************************/
      
    • Anuj Behl

      If you don't find much in documentation, there's a blog post detailing how to write a first CPM which might help you.

    • Marv Ferrer

      I find the blog post very clear and useful. All developer documentation should always be well written with working examples. Time is money and we don't have enough of it for lengthy trial and error.

      Thanks, Anuj!

    • Suresh Thirukoti

      You are right Marv........most of the ppl find the blog post to be more readable than the actual documentation.....I think RNT KB folks need to understand this and update accordingly!!! We always refer to cxdeveloper.com than documentation.custhelp.com for CPMs ...CP documentation is heights of confusion ... 

      ~Suresh

    • Dietrik

      Feel free to post commented examples on the forum. Unfortunately not much people are willing to share examples.

    • Marv Ferrer

      By the way, is this how you set a custom field? For some reason, it's not setting it at all when I create/update an incident. Is there another syntax?

      $object->CustomFields->c->the_custom_field

    • Suresh Thirukoti

      Marv - This applies to straight forward assignments like Integer or Text data types .....but for menu type, it should be like 

      $object->CustomFields->c->the_custom_field =new RNCPHP\NamedIDOptList();

      $object->CustomFields->c->the_custom_field->ID = <>;

      or

      $object->CustomFields->c->the_custom_field =new RNCPHP\NamedIDLabel();

      $object->CustomFields->c->the_custom_field->LookupName = "<label representation>";

      ~Suresh

    • Marv Ferrer

      Yes, I'm trying to set a value for a Text Area field type. I also made sure that the event handler is assigned to Create/Update in the Incident Object. I'm probably missing something here.

       

    • Suresh Thirukoti

      If you can post the code so we can check it out...

       

    • Marv Ferrer

      It looks like this:

              public static function
              apply( $run_mode, $action, $obj, $cycles )
              {
                      if ($cycle !== 0) return;
                      
                      if (RNCPM\ActionUpdate == $action):
                              $obj->CustomFields->c->api_log = 'update';
                              $obj->save();                        
                              RNCPHP\ConnectAPI::commit();            
                      elseif (RNCPM\ActionCreate == $action):
                              $obj->CustomFields->c->api_log = 'create';
                              $obj->save();
                              RNCPHP\ConnectAPI::commit();            
                      endif;
                      
                      //print $obj->ID;
              return;
              } // apply()
      
    • Suresh Thirukoti

      Can you do this way and check ..bcoz I feel your code looks fine or something amiss...

      $inc = RNCPHP\Incident::fetch($obj->ID);
      $inc->CustomFields->c->testta = "update";
      $inc->save(RNCPHP\RNObject::SuppressAll);

      ~Suresh

    • Marv Ferrer

      Still nothing... sad

    • Anuj Behl

      Marv,



      I've been there too, check this post. In essence, you will have to use ROQL for custom fields.



      -Anuj

    • Marv Ferrer

      Thanks, Anuj. I have experience with ROQL and I know for sure it will work. However, this piece in the documentation where it tells you that it's possible to set values for custom fields should be brought up. I'm assuming all other developers out there are using the ROQL workaround. My main point is, if it's in the documentation, it should work as stated. Period.