PHP, SugarCRM, Javascript, Cool Web Apps Developer


Create Document in Sugar

Posted by swapnil shinde on December 11, 2012 at 12:10 AM Comments comments (0)

We can create or upload the document in sugarcrm using soap.

I was finiding a way to create a doc from backend. right now its from raw PHP code, I will post the code based on Sugarcrm's convention, I mean using objects soon.

Here is the code.

if(!defined('sugarEntry')) define('sugarEntry',true);


global $db;

$doc_guid=create_guid(); //////create sugar id for doc

$doc_revision_guid=create_guid(); //////////create sugar id for doc revision

$filename="upload/".$doc_revision_guid; //////create file in sugar's upload dir

$OpenDoc = fopen($filename,'w');

$writ_to_doc="Yo"; //////content to write to file

fwrite($OpenDoc,$writ_to_doc); //////write to file

///////////insert into documents module

$qry="INSERT INTO documents (id, date_entered, date_modified, modified_user_id, created_by, description, deleted, assigned_user_id, team_id, team_set_id, document_name, doc_id, doc_type, doc_url, active_date, exp_date, category_id, subcategory_id, status_id, document_revision_id, related_doc_id, related_doc_rev_id, is_template, template_type) VALUES ('$doc_guid', now(), now(), '1', '1', '', 0, '1', '1', '1', 'Neels.doc', '', 'Sugar', '', '2012-08-24', NULL, '', '', 'Active', '$doc_revision_guid', '', NULL, 0, '')";


///////////insert into documents revions module

$qry="INSERT INTO document_revisions (id, change_log, document_id, doc_id, doc_type, doc_url, date_entered, created_by, filename, file_ext, file_mime_type, revision, deleted, date_modified) VALUES ('$doc_revision_guid', 'Document Created', '$doc_guid', '', 'Sugar', '', now(), '1', 'Neels.doc', 'doc', 'application/msword', '1', 0, now())";