AnsweredAssumed Answered

Custom entry point and $bean->save() method crashing

Question asked by Josh Wright on Feb 21, 2019
Latest reply on Feb 21, 2019 by Francesca Shiekh

Hello all, I had an issue with an entry point when trying to save a bean. I have tried disabling row level security and moving the save earlier and later within the code. For some reason, whenever I try to save the contact within the entry point it crashes the request and nothing happens.

 

This is my code:

 

<?php
if (!defined('sugarEntry') || !sugarEntry) die ('Not a valid Entry Point');

global $current_user;


date_default_timezone_set('America/New_York');

$call = BeanFactory::newBean('Calls');
$module = $_POST['module'];
$parent_id = $_POST['parent_id'];
$call_outcome_c = '';
//check if module is $oContacts
if ($module == 'Contacts') {
$contact_bean = BeanFactory::retrieveBean("Contacts", $parent_id);
$contact_bean->disable_row_level_security = true;

$target_list_id = $_REQUEST['target_list_id']; // get target list
$target_list = BeanFactory::retrieveBean("ProspectLists", $target_list_id);

$call->parent_type = "Contacts";
$call->parent_id = $parent_id;

if (!empty($_POST['description'])) {
$call->description = $_POST['description'];
}
//check if call outcome
if (isset($_POST['call_outcome_c'])) {
$call_outcome_c = $_POST['call_outcome_c'];

$call->call_outcome_c = $call_outcome_c;

$contact_bean->description .= "\n" . "\n" . $target_list->name . " - " . date('m/d/Y h:ia') . "\nCall Made by " . $current_user->full_name . " with outcome of " . $call_outcome_c . "\nDescription:" . $_POST['description'] . "\n";
//set contact call putcome to most recent call outcome
$contact_bean->call_outcome_c = $call_outcome_c;

$contact_bean->save(); // <<< This is the line of code in question, if I comment this out it will work correctly.
}
$call->assigned_user_id = $current_user->id;
$call->assigned_user_name = $current_user->full_name;
$call->direction = "Outbound";
$call->status = "Held";
$call->date_start = date('m/d/Y h:ia');


if($contact_bean->account_id != ""){
$contact_account = BeanFactory::retrieveBean("Accounts",$contact_bean->account_id);
if(isset($contact_account->name) && !empty($contact_account->name)){
$call->account_c = $contact_account->name;
}
}

//get prospect list bean and load relationship between it and campaigns
$target_list->load_relationship('atc_isscampaigns_prospectlists_1');
//pull campaign bean
$prospect_list_relation = $target_list->atc_isscampaigns_prospectlists_1->getBeans();
$campaign_bean = current($prospect_list_relation); //populate campaign bean to pull name

$call->campaign_name_c = $campaign_bean->name;

$call->direct_phone_c = $contact_bean->phone_other;

$call->name = "Made call to " . $contact_bean->full_name;
$call->save();

//Relate beans
$target_list->load_relationship('prospectlists_calls_1');
$target_list->prospectlists_calls_1->add($call->id);

$campaign_bean->load_relationship('atc_isscampaigns_calls_1');
$campaign_bean->atc_isscampaigns_calls_1->add($call->id);

//relate call to contacts using custom fields because regular relation doesn't work

$columns = array("call_id" => $call->id, "contact_id" => $parent_id);
$values = array($call->id, $parent_id);
$call->set_relationship('calls_contacts', $columns, true, false, $values);
}
//value to return to call_logging.js
$ret = array('message' => $msg, 'row_id' => $parent_id, 'call_outcome' => $call_outcome_c, 'module' => $module);
echo json_encode($ret);

?>

Outcomes