Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Chandra Prasad
    Custom Process - prev unable to access values
    Topic posted August 12, 2019 by Chandra Prasad 
    18 Views, 5 Comments
    Title:
    Custom Process - prev unable to access values
    Summary:
    $obj->prev throwing error as "Trying to get property of non-object"
    Content:
    I have checked a similar post,but it didn't solve the issue.If i use isset($obj->prev),its empty.Sample snippet which i used.

     

     public static function apply($runMode, $action, $obj, $cycle)

    {

    if (isset($obj))
        {
    $var=$obj->Name->First;  
    $pvar=$obj->prev->Name->First;
    if ($var != $pvar) {
    ...
    ...
    }
    }
    }

    Comment

     

    • Sristy Arya

      Hi Chandra,

       

      Can you give some clarity : CPM is being triggered for Incident or Opportunities ?  If possible share the code to debug along with the field detail you are trying to access.

       

      Thanks

      Sristy  

      • Chandra Prasad

        Hi Sristy,

        CPM is being triggered for Contact update.

        <?php
        /**
         * CPMObjectEventHandler: ContactHandler
         * Package: RN
         * Objects: Contact
         * Actions: Update
         * Version: 1.3
         * Purpose: CPM handler for contact create and update.
         */
         
        use \RightNow\Connect\v1_3 as RNCPHP;
        use \RightNow\CPM\v1 as RNCPM;
         
         
        class ContactHandler implements RNCPM\ObjectEventHandler
        {
         
            /**
             * Apply CPM logic to object.
             * @param int $runMode
             * @param int $action
             * @param object $obj
             * @param int $cycle
             */
            public static function apply($runMode, $action, $obj, $cycle)
            {
         
        $var1=$obj->Name->First;
        $var2=$obj->Name->Last;
         
        if (isset($obj))
            {
         
        $var1=$obj->Name->First;
        $var2=$obj->Name->Last;
           
        $pvar1=$obj->prev->Name->First;
        $pvar2=$obj->prev->Name->Last;
        if(isset($pvar1)){
                if ($var1 != $pvar1) {
        try{
                    $custom1 = new RNCPHP\CO\CustomContact();
        $custom1->ContactID= $obj->ID;  
                    $custom1->FieldName= "First Name";
                $custom1->FieldValue= $pvar1;
                    $custom1->save(RNCPHP\RNObject::SuppressAll);
        }
         
                        catch (Exception $err ){
                            echo $err->getMessage();
                            }
        }}
        if(isset($pvar2)){
        if ($var2 != $pvar2) {
        try{
                    $custom1 = new RNCPHP\CO\CustomContact();
        $custom1->ContactID= $obj->ID;  
                    $custom1->FieldName= "Last Name";
                $custom1->FieldValue= $pvar2;
                    $custom1->save(RNCPHP\RNObject::SuppressAll);
        }
         
                        catch (Exception $err ){
                            echo $err->getMessage();
                            }
                }
        }
         
         
            }   
        }
        }
         
         
         
        *CustomContact is a Custom object
         
        Thanks,
        Chandra
        • Lakshay Bhalla

          Hi Chandra,

          Please attach the Complete CPM for RCA.

          And i would suggest to use the Best Practices and Gotchas for CPMs such as Exception handling. Link: https://cx.rightnow.com/app/answers/detail/a_id/9640/track/AvM9zwqoDv8S~fPaGpRy~6LwenU6~S75Mv8O~zj~PP~H

          Use "\" in the catch like: catch(\Exception $ex).

          Thanks

          Lakshay

    • Suresh Thirukoti

      I had this prev issue earlier so I tried below and it worked...so you can also try and check

       

       if (isset($obj)) {

       .....................

         if (isset($obj->prev)) {

      //assignment and further action on prev object

      }

      }

      ~Suresh

      • Chandra Prasad

        Hi Suresh,

           if (isset($obj->prev)) --> isn't throwing error but, the content inside 'if' condition is no getting executed as (isset($obj->prev)) is empty.

         

        Thanks,
        Chandra