AnsweredAssumed Answered

Create a document record, relate it to a Contact, upload a file as a revision to that Document using an entrypoint and POST data

Question asked by Rob Douglas on May 14, 2015
Latest reply on May 20, 2015 by paperless
Sugar 6.5.16 Pro, in house

Hi everyone

We have an online form that POST's data to our Sugar installation, the data is processed via an entrypoint Part of the POST data  is a URL to an uploaded CV/Resume. I'd like to know if anyone has pointers to code that can help me
  1. Create a new document record in Sugar and relate that document to a contact record. The contact id (sugar id field) is parsed in with the POST data
  2. Create a revision? (1) that will upload the document from the URL referenced in the POST data to the previously created Sugar Document record
I have partially completed, that is, my code is creating the record, but doesn't create the relationship and I haven't started on the upload/revision part yet. Code is below, thanks in advance for any assistance anyone can give me :=]

Variables in the following code have been created earlier in the script e.g. $resumepath, $firstname etc

// Create a document to store the CV
$document = new Document();
$document->parent_type = "Contacts";
$document->contact_id = $sugarid;
$document->parent_id = $sugarid;
$document->assigned_user_id = $assigned_user_id;
$document->modified_user_id = $assigned_user_id;
$document->created_by = $assigned_user_id;
$document->document_name = "Resume-".$firstname." ".$lastname;
$document->category_id = "Personal Documentation";
$document->subcategory_id = "Resume";
$document->description = "Document record created by online form to hold CV/Resume uploaded to ".$resumepath;
// Path to uploaded resume from online form
$document->doc_url = $resumepath;
// Create revision code, upload file to Sugar upload directory