views:

18

answers:

1

Hello all, I've got this custom button on Lead Editview that when clicked on generates (via AJAX) an invoice number and a PDF bearing the same number.

In the next step, the routine uses SOAP to loopback to Sugar and creates a Note (along with the PDF as attachment).

My question is can I avoid this SOAP call and use some other internal mechanism / classes to do the same? Something along the lines of

$invoice = new Note();
$invoice->create(....);
...

if you get my drift.

Is this possible? I couldn't find any documentation anywhere... all roads seem to point to SOAP.

Thanks,

A: 

Hi,

If your Ajax call is performing a db update/save operation, then you could look into using a after_save logic hook.

EDIT: for eg: you could try out this code, have a look at the code in <sugar_root>/modules/Notes/Note.php

$note = new Note();
$note->modified_user_id = $current_user->id;
$note->created_by = $current_user->id;
$note->name = 'New';
$note->parent_type = "Accounts";
$note->parent_id = $bean->parent_id;
$note->description = $bean->description;
$note->save();

As far as attachment goes, it's a bit tricky. Sugar expects the attachment to be a upload_file object. Have a look at the code in <sugar_root>/modules/Notes/controller.php the function action_save() and <sugar_root>/include/upload_file.php

HACK: this is not the correct way but it works. With a slight modification to the code above and cunning use of the move function , you could make the attachment work. Sugar stores the attachments in cache/upload folder with the ID of the note created.

$note->filename = "Yourfilename.txt" //your file name goes here
$note->file_mime_type = "text/plain"  // your file's mime type goes here
$new_note_id = $note->save();

move(your_file_location, cache/upload/$new_note_id)
//don't add a extension to cache/upload/$new_note_id

HTH

P.S: untested code

Anand
Hello Anand, I know about after_save and am using it in several places. However, in this case I'm trying to figure out if a NOTE can actually be created by instantiating a NOTE object and using any members methods to create the note and attach a file to it - instead of doing it via SOAP.
miCRoSCoPiC_eaRthLinG
Hi, I've edited my answer. Hope it helps :)
Anand