AnsweredAssumed Answered

Date Created not set on new beans in custom endpoint

Question asked by Artis Plocins on Aug 17, 2017
Latest reply on Aug 18, 2017 by Francesca Shiekh

I have ac ustom endpoint without authentication in which a case record is created. The problem is that the Date Created field shows "No Data" on the case records created through this script. I thought it was supposed to set the date created automatically.


Here is the whole case creation code block.


// SugarQuery is used to find the corresponding case by the ticket ID
$sq = new SugarQuery();
$sq->from(BeanFactory::newBean('Cases'), array('team_security' => false));
$sq->where()->equals('ticket_id_c', (int) $ticket['id']);
$result = $sq->execute();

if (count($result) == 0) { // Case does not exist, create new
    $case = BeanFactory::newBean('Cases');
} else { // Case exists, update fields
    $case = BeanFactory::getBean('Cases', $result[0]['id'], array('disable_row_level_security' => true));
$case->ticket_id_c = $ticket['id'];
$case->name = $ticket['subject'];
$case->agent_name_c = $ticket['agent']['name'];
$case->agent_team_c = $ticket['agent_team']['name'];
$case->complaint_c = $ticket['field1']; // Custom field: Type of Complaint
$case->product_c = $ticket['product']['title'];

switch ($ticket['status']) {
    case 'awaiting_user':
        $case->status = 'Pending Input';

    case 'awaiting_agent':
        $case->status = 'Pending Input';

    case 'resolved':
    case 'archived':
        $case->status = 'Closed';

$email = $ticket['person']['primary_email']['email'];
$email = strtoupper($email);
// BUG: Both SugarQuery and SugarEmailAddress returned only the Users record
// while their compiled queries returned 3 records in the database,
// so the DBManagerFactory had to be used with the generated SQL.
$sql = "SELECT id FROM contacts
        INNER JOIN email_addr_bean_rel jt1_email_addr_bean_rel
        ON ( = jt1_email_addr_bean_rel.bean_id AND jt1_email_addr_bean_rel.deleted = 0 AND jt1_email_addr_bean_rel.bean_module = 'Contacts')
        INNER JOIN email_addresses jt0_email_addresses ON ( = jt1_email_addr_bean_rel.email_address_id AND jt0_email_addresses.deleted = 0)
        LEFT JOIN contacts_cstm ON contacts_cstm.id_c =  WHERE contacts.deleted = 0 AND jt0_email_addresses.email_address_caps LIKE '%$email%'";
$contactId = $GLOBALS['db']->getOne($sql);

$contact = BeanFactory::getBean('Contacts', $contactId, array('disable_row_level_security' => true));
$case->account_id = $contact->account_id;

// Assign to the Global team



Am I missing something that enables Date Created to be set? It can't be that we have to set it manually in every script?