Javascript sugarcrm向to_集合添加电子邮件地址

Javascript sugarcrm向to_集合添加电子邮件地址,javascript,sugarcrm,Javascript,Sugarcrm,我一直在尝试通过代码向电子邮件模型的to_collection字段添加电子邮件地址。 to_集合已经有一些方法,如添加、创建、删除。我正在尝试使用创建函数,但每当我使用to_集合模型中存在的电子邮件地址时,它都会设置为空 这就是我要做的 var email = app.data.createBean('Emails', {id: <email_id> }); email.fetch({ view:'record', success:__bind(funct

我一直在尝试通过代码向电子邮件模型的to_collection字段添加电子邮件地址。 to_集合已经有一些方法,如添加、创建、删除。我正在尝试使用创建函数,但每当我使用to_集合模型中存在的电子邮件地址时,它都会设置为空

这就是我要做的

var email = app.data.createBean('Emails', {id: <email_id> });
email.fetch({
       view:'record',
       success:__bind(function (data) {
           console.log('[TEST]',data);
           var prefill = app.data.createBean('Emails');
           prefill.copy(data);
           prefill.unset("to_collection");
           var to_col = data.get('from_collection').models[0];
           to_col.link.name = 'to';
           to_col.set('_link','to');               
           var t = data.get('to_collection');
           //t.create(to_col)

      },this)
})
如果我使用
t.create(to_col)

它显示空白的
电子邮件地址:“


在糖7.9中测试

由于这是我们正在讨论的一个抽屉,您只需将地址作为
context.prepopulate.to_addresses
array传递,Sugar将用它们预先填充to:input栏。如果用户未将其删除,则在保存时会将其添加到
to_集合

例如,在浏览器的JS控制台中尝试以下操作(在Sugar中):

在糖7.11中测试

在post-7.9电子邮件模块中,似乎有必要使用预先存在的电子邮件地址bean

有一个utils函数,它将打开抽屉并接受
数据
参数对象中电子邮件地址Bean集合的/cc/bcc数组(或属性数组)

openEmailCreateDrawer: function(layout, data, onClose)
因此,由于您已经拥有来自不同型号的to_集合,您可以执行以下操作:

App.utils.openEmailCreateDrawer(
    'compose',
    {
        to: data.get("to_collection")
    }
)
还可以使用相同的
数据
参数预先填充主题、html正文和附件

e、 g.使用您的变量可以如下所示:

app.utils.openEmailCreateDrawer(
    'compose-email',
    {
        to: data.get("to_collection"),
        name: subject,
        description_html: body,
        attachments: attachments
    }
)
这是基于
utils.js
中负责解析上述函数的
数据的helper函数的注释:

    /**                                                                      
     * Populates attributes on an email from the data provided.              
     *                                                                       
     * @param {Date.Bean} email                                              
     * @param {Object} data Attributes to set on the email.                  
     * @param {string} [data.name] Sets the subject of the email.            
     * @param {string} [data.description_html] Sets the HTML body of the     
     * email.                                                                
     * @param {Array|Data.BeanCollection|Data.Bean} [data.from_collection]   
     * The sender to add to the From field.                                  
     * @param {Array|Data.BeanCollection|Data.Bean} [data.from] A more       
     * convenient alternative name for the sender.                           
     * @param {Array|Data.BeanCollection|Data.Bean} [data.to_collection]     
     * The recipients to add to the To field.                                
     * @param {Array|Data.BeanCollection|Data.Bean} [data.to] A more         
     * convenient alternative name for the To recipients.                    
     * @param {Array|Data.BeanCollection|Data.Bean} [data.cc_collection]     
     * The recipients to add to the CC field.                                
     * @param {Array|Data.BeanCollection|Data.Bean} [data.cc] A more         
     * convenient alternative name for the CC recipients.                    
     * @param {Array|Data.BeanCollection|Data.Bean} [data.bcc_collection]    
     * The recipients to add to the BCC field.                               
     * @param {Array|Data.BeanCollection|Data.Bean} [data.bcc] A more        
     * convenient alternative name for the BCC recipients.                   
     * @param {Array|Data.BeanCollection|Data.Bean} [data.attachments_collection]
     * The attachments to attach to the email.                               
     * @param {Array|Data.BeanCollection|Data.Bean} [data.attachments] A     
     * more convenient alternative name for the attachments.                 
     * @param {Data.Bean} [data.related] A convenience for relating a        
     * parent record to the email.                                           
     * @return {Object} Any key-values pairs that could not be assigned are  
     * returned so the caller can decide what to do with them.               
     */                                                                      
    function prepopulateEmailForCreate(email, data) {

我确实通过以下方法解决了这个问题

prefill.get('to_collection').create({
      deleted: false,
      email_address: to_coll.get('email_address'),
      email_address_id: to_coll.get('email_address_id'),
      _link: "to"
 });

但是,我不知道这是否正确。

您需要什么功能,请您解释一下。我只想在电子邮件模型的“收件人”集合字段中添加一个电子邮件地址,作为回复电子邮件。您是否尝试过,JS代码在哪里?什么文件?还有,你用的是什么版本?嗯,这对我不起作用,嗯,我明白了。当时我只有7.9可用。他们一定在7.10中改变了一些事情,我会看看是否能得到一个更新的实例,然后再联系你。我要弄清楚它在7.11中是如何工作的,并更新了我的答案-请在7.10中尝试一下这个解决方案,并让我知道它是否工作:)该死,我在7.10.0.0上测试了,在控制台中的第一个代码对我不起作用。让我检查一下7.11中的另一个问题,您在另一个问题中提到您使用的是较新的版本,因此即使尝试7.9,也确实是我的错,因为知道电子邮件模块在7.10中发生了很大变化(它从传统模式转移到Sugar 7 UI框架)。我只是假设/希望抽屉本身没有太大变化,因为抽屉已经是新UI的一个功能了,但显然他们修改了所有关于电子邮件模块的内容,抽屉确实发生了变化^^^'所以是的,很抱歉之前浪费了你的时间,我希望新代码能起到作用:)
    /**                                                                      
     * Populates attributes on an email from the data provided.              
     *                                                                       
     * @param {Date.Bean} email                                              
     * @param {Object} data Attributes to set on the email.                  
     * @param {string} [data.name] Sets the subject of the email.            
     * @param {string} [data.description_html] Sets the HTML body of the     
     * email.                                                                
     * @param {Array|Data.BeanCollection|Data.Bean} [data.from_collection]   
     * The sender to add to the From field.                                  
     * @param {Array|Data.BeanCollection|Data.Bean} [data.from] A more       
     * convenient alternative name for the sender.                           
     * @param {Array|Data.BeanCollection|Data.Bean} [data.to_collection]     
     * The recipients to add to the To field.                                
     * @param {Array|Data.BeanCollection|Data.Bean} [data.to] A more         
     * convenient alternative name for the To recipients.                    
     * @param {Array|Data.BeanCollection|Data.Bean} [data.cc_collection]     
     * The recipients to add to the CC field.                                
     * @param {Array|Data.BeanCollection|Data.Bean} [data.cc] A more         
     * convenient alternative name for the CC recipients.                    
     * @param {Array|Data.BeanCollection|Data.Bean} [data.bcc_collection]    
     * The recipients to add to the BCC field.                               
     * @param {Array|Data.BeanCollection|Data.Bean} [data.bcc] A more        
     * convenient alternative name for the BCC recipients.                   
     * @param {Array|Data.BeanCollection|Data.Bean} [data.attachments_collection]
     * The attachments to attach to the email.                               
     * @param {Array|Data.BeanCollection|Data.Bean} [data.attachments] A     
     * more convenient alternative name for the attachments.                 
     * @param {Data.Bean} [data.related] A convenience for relating a        
     * parent record to the email.                                           
     * @return {Object} Any key-values pairs that could not be assigned are  
     * returned so the caller can decide what to do with them.               
     */                                                                      
    function prepopulateEmailForCreate(email, data) {
prefill.get('to_collection').create({
      deleted: false,
      email_address: to_coll.get('email_address'),
      email_address_id: to_coll.get('email_address_id'),
      _link: "to"
 });