Create new SugarCRM record in logic hook

sugarcrmdevelopers —  February 18, 2011

Editor’s Note: This is another post from the blog of Sugar Community member Milos Miric, re-posted with his permission. In this post he shows how to create a new record thru a logic hook.

SugarCRM 6.0 ent

Goal: create a new record of any module in logic hook

Steps: Create a logic hook. In the file where you define the function for logic hook use the following code to replicate making a new object (record) and saving it.

<?php

class CreateCall{

// function we call in the logic hook definition, for our example i used creating call after making contact

function callManager(&$bean, $event, $arguments) {

// as contact you can create any other object of any other module

// create a new Call object (represents a record)
$call = new Call();
// fill in record data
$call->assigned_user_id = "1";
$call->assigned_user_name = "Administrator";
$call->name = "call manager";
$call->direction = "Outbound";
$call->status = "Planned";
$call->date_start = "25/08/2010 18:45";
$call->duration_minutes = "15";
// this values can also be taken from db as well as any other value, just example
$call->team_id = "3d6f0dab-6e7d-c801-b2e9-4c73b6226647";
$call->team_name = "Administrator";
$call->description = "please call your manager and superior and report for work!";

// this is called in the end to save entry, and your new record in Calls will be created with data above
$call->save();

  }

}

?>

It should be upgrade safe unless of course you want to populate fields in Call that does not exist.

Share