代码之家  ›  专栏  ›  技术社区  ›  miCRoSCoPiC_eaRthLinG

SugarCRM:创建没有肥皂的带有附件的笔记?

  •  2
  • miCRoSCoPiC_eaRthLinG  · 技术社区  · 15 年前

    我在LeadEditView上有一个自定义按钮,当单击它时(通过Ajax)会生成一个发票号和一个具有相同编号的PDF。

    在下一步中,该例程使用SOAP循环返回到Sugar,并创建一个注释(连同PDF作为附件)。

    我的问题是,我是否可以避免这个SOAP调用,并使用其他内部机制/类来执行相同的操作?有点像

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

    这有可能吗?我找不到任何文档…所有的道路似乎都指向肥皂。

    1 回复  |  直到 10 年前
        1
  •  4
  •   Anand Shah    15 年前

    如果Ajax调用正在执行数据库更新/保存操作,那么可以使用 after_save 逻辑钩子。

    编辑: 例如:你可以试试这个代码,看看里面的代码 <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();
    

    就附件而言,有点棘手。Sugar希望附件是上载文件对象。看看里面的代码 <sugar_root>/modules/Notes/controller.php 函数 action_save() <sugar_root>/include/upload_file.php

    乱劈: 这不是正确的方法,但它起作用。稍微修改上面的代码并巧妙地使用 move 功能,您可以使附件工作。糖把附件储存在 cache/upload 已创建便笺ID为的文件夹。

    $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
    

    高温高压

    P.S:未测试代码

    推荐文章