1. 不能 将现有的音符记录与电子邮件记录相关联。这将按预期抛出API中的异常。用作3d彩吧论坛的注意只能存在一次,并且不能作为多电子邮件的3d彩吧论坛。
  2. 能够 create a new Note record that uses an existing Note's attached file. Doing so essentially requires setting the upload_id field of the new Note record to the id of the existing Note you want to reuse the file from, and setting the file_source field of the new Note to 'Notes'. In addition to needing to set the upload_id, you must also set the filename and name field.

以下示例演示了如何在三个不同的上下文中执行此操作:服务器端(SugarBean / PHP),客户端(Sidecar / JavaScript),纯粹通过API。但所有三个语境都遵循相同的必要步骤:

  1. 获取原始注释记录;
  2. 创建一个新的音符记录,从原始注释记录设置必要的字段;
  3. 通过相应的“3d彩吧论坛”链接将新的音符记录链接到电子邮件记录。



$original_note_id = '4e226282-8158-11e8-a1b3-439fe19c087a';
$email_id = 'e3e058f4-7f11-11e8-ba11-fcdd97d61bbe';

// 1. Fetch Original Note:
$original_note = BeanFactory::retrieveBean('Notes', $original_note_id);

// 2.  Create a new note based on original note, setting upload_id, name, and filename:
$new_note = BeanFactory::newBean('Notes');
$new_note->upload_id = $original_note->getUploadId();
$new_note->file_source = 'Notes';
$new_note->filename = $original_note->filename;
$new_note->name = $original_note->filename;

// 3. Relate the new note to Email record using 'attachments' link:
$email = BeanFactory::retrieveBean('Emails', $email_id);
$email->attachments->add($email, $new_note);

笔记 that in most contexts, such as a Logic Hook or a custom endpoint, you will not need to call save() on either the $new_note or $email for $new_note to be related as an attachment to $email and for $new_note to save. The $new_note record will save as part of being linked to $email.


The following example is totally standalone within Sidecar, demonstrating how to fetch the existing Note using and bean.fetch(), create the new Note using and setting the relevant fields, and then adding the new Note to the email records attachments_collection.

var original_note_id = '4e226282-8158-11e8-a1b3-439fe19c087a';
var email_id = 'e3e058f4-7f11-11e8-ba11-fcdd97d61bbe';

// 1. Fetch Original Note:
var original_note ='Notes');
original_note.set('id', original_note_id);

// 2.  Create a new note based on original note, setting upload_id, name, and filename:

var new_note ='Notes', {
	_link: 'attachments',
	upload_id: original_note.get('id'),
	file_source: 'Notes',
	filename: original_note.get('filename'),
	name: original_note.get('filename'),
	file_mime_type: original_note.get('file_mime_type'),
	file_size: original_note.get('file_size'),
	file_ext: original_note.get('file_ext'),

// 3.  Relate the new note to Email record using 'attachments_collection' link:

var email ='Emails');
email.set('id', email_id);


笔记: In the above example, the fields file_mime_type, file_size, and file_ext are also set. This is assuming a context where the customization is adding the attachments to the Compose Email view. Setting these fields makes the new attachments look correct to the user before saving the Email, but these fields are otherwise set automatically on save. If extending the actual compose view for emails, you also wouldn't fetch the email directly. This is added in this example purely for demonstration purposes.


The following section will outline how to related the attachment using the REST API using the /link/attachments/ endpoint for the Email record.


To fetch the original note, send a GET request to rest/{REST VERSION}/Notes/{$original_note_id}. An example of the response is shown below :

  "id": "4e226282-8158-11e8-a1b3-439fe19c087a",
  "name": "笔记 with Attachment",
  "date_entered": "2018-07-01T12:00:00-00:00",
  "description": "Send to special clients.",
  "file_mime_type": "application/pdf",
  "filename": "special_sales_doc.pdf",
  "_module": "笔记s"


Create a JSON object based on the response (which we will treat as a JSON object named $original_note) like:

	"upload_id": "$",
	"file_source" : "笔记s"
	"name" : "$original_note.filename",
	"filename" : "$original_note.filename",

Relate the Note to the Email record using the 'attachments' link. Next, send a POST request to rest/{REST VERSION}/Emails/{$email_id}/link/attachments/ with the JSON shown above as the request body.

最后修改:2021-02-17 02:44:13