3

I am trying to get data out of the API and when I look at it in API explorer I find what I am looking for but the data is incomplete in my module.

For example, I am using civicrm_post($op, $objectName, $objectId, &$objectRef) and I know this is working because I have if ($objectName != "Case" || $op != "create") and my code in the if is firing.

    civicrm_initialize();
$result = civicrm_api3('Case', 'get', array(
          'sequential' => 1,
          'id' => $objectId,
          ));

Here is the result from the API call in my module:

Array

( [is_error] => 0 [version] => 3 [count] => 1 [id] => 352 [values] => Array ( [0] => Array ( [id] => 352 [case_type_id] => 5 [subject] => Test Case Subject [start_date] => 2017-07-24 [status_id] => 4 [is_deleted] => 0 [contact_id] => Array ( )

                [client_id] => Array
                    (
                    )

                [contacts] => Array
                    (
                    )

                [activities] => Array
                    (
                    )

            )

    )

)

Here is the result from the API Explorer:

{

"is_error": 0,
"version": 3,
"count": 1,
"id": 352,
"values": [
    {
        "id": "352",
        "case_type_id": "5",
        "subject": "Test Case Subject",
        "start_date": "2017-07-24",
        "status_id": "4",
        "is_deleted": "0",
        "custom_70": "IL",
        "custom_72": "Peoria County",
        "custom_76": "1",
        "custom_78": "2",
        "custom_92": "Farmers",
        "custom_100": "1500943386-26151211",
        "custom_95": "Test",
        "custom_96": [
            "1"
        ],
        "custom_97": [
            "1"
        ],
        "custom_98": [
            "1"
        ],
        "custom_99": [
            "1"
        ],
        "contact_id": {
            "1": "9025"
        },
        "client_id": {
            "1": "9025"
        },
        "contacts": [
            {
                "contact_id": "9025",
                "sort_name": "Applications , Test",
                "display_name": "Test Applications",
                "email": "[email protected]",
                "phone": "",
                "birth_date": "1919-04-04",
                "role": "Client"
            }
        ],
        "activities": [
            "21781",
            "21782"
        ]
    }
]

}

Any help is appreciated.

Thanks, Josh

4
  • Can you please say more about which data is showing up in the api explorer that's not showing up in $result when your code runs? (maybe edit your question to include the two different results?) Commented Jul 25, 2017 at 1:29
  • At exactly the same point in the process? Commented Jul 25, 2017 at 12:03
  • @NoahMiller I have added the results. I was trying not to make the post so long.
    – Josh
    Commented Jul 25, 2017 at 17:50
  • @ErikH-CiviCooP I added sleep (30) to try and get it as close as possible and I still get the same results.
    – Josh
    Commented Jul 25, 2017 at 17:52

2 Answers 2

2

At the point hook_post is called the timeline (activities) hasn't been created and the association with the client (CaseContact object) hasn't either.

See https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/Case.php and https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/Activity/OpenCase.php

7
  • do you know if there is an API call that will do this or do I need to do an SQL query directly on the database? Thanks!
    – Josh
    Commented Jul 25, 2017 at 17:54
  • Neither api nor sql will get you anything at that point since it isn't in the database yet. You could store the case id somewhere and do hook post on CaseContact when that arrives and compare its case id. But what is your end goal? Maybe a cron hook is better?
    – Demerit
    Commented Jul 26, 2017 at 1:29
  • Or try the postProcess hook instead on the case form object.
    – Demerit
    Commented Jul 26, 2017 at 1:37
  • 2
    That is the reason I asked if it was at exactly the same point in the process :-) The Case transaction is completed right at the end and before that most stuff is not in the database yet! Cost me quite a bit of headache in the past.....:-) Commented Jul 26, 2017 at 6:36
  • @Demerit When I look at the documentation I am not sure what hook that is. Which hook are you talking about? Thanks!
    – Josh
    Commented Jul 26, 2017 at 19:26
1

So that is it clear for others in the future ErikH has the answer above in the comments.

That is the reason I asked if it was at exactly the same point in the process :-) The Case transaction is completed right at the end and before that most stuff is not in the database yet! Cost me quite a bit of headache in the past.....:-) – ErikH - CiviCooP Jul 26 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.