AnsweredAssumed Answered

email attachment custom in custom module 7.10 / 7.11

Question asked by Humberto Ribeiro de Souza on Mar 1, 2018

Hi,

 

I am facing issue when adapting a code that worked until the version 7.8. 

We decided to update in to the OnDemand versions 7.10 and 7.11 knowing that there was a framework update in the email module.

Now, I am trying to call an AJAX from shareaction.js and attach the PDF I generate or get in the call.

 

Am I missing something at this point? 

Notice that I have duplicated the function in order to work in both versions - 7.10 and 7.11 - with no success so far. The attachment appears there with 0K and it is not sent at all. I put the critical part in bold

 

Thank you in advance

 

-----------------------

* Share row action.
*
* This allows an user to share a record that is currently mapped with this
* field context.
*
* @class View.Fields.Base.ShareactionField
* @alias SUGAR.App.view.fields.BaseShareactionField
* @extends View.Fields.Base.EmailactionField
*/
({
extendsFrom: 'ShareactionField',

initialize: function(options) {
this._super('initialize', [options]);
},

_setShareOptions: function() {
var shareParams = this._getShareParams(),
subject = this.shareTplSubject(shareParams),
body = this.shareTplBody(shareParams),
bodyHtml = this.shareTplBodyHtml(shareParams);

// this generates my PDF successfully
//attachment_pdf = app.bwc.buildRoute(this.module,this.model.get('id'),'sugarpdf',{sugarpdf:'visitesgenerale'});

// Generate the PDF and return a document ID
var gateway = 'save_vg_pdf';

filename1 = 'Rapport: ' + this.model.get('name');

var document_id = '';

request = new XMLHttpRequest();


$.ajax({
beforeSend: function (request)
{
request.setRequestHeader("OAuth-Token", SUGAR.App.api.getOAuthToken());
App.alert.show('wait', {
level: 'process',
messages: 'Generation du PDF'
});
},
url: "rest/v10/"+gateway+"/"+this.model.get('id') ,

dataType: "json",
type: "GET",
// WAS GET
async:false,
success: function(doc_id)
{
App.alert.dismissAll();
document_id = doc_id;

},
error: function(){
App.alert.dismissAll();
app.alert.show('server-error',
{
level: 'error',
messages: 'ERR_GENERIC_SERVER_ERROR'
});
}
});

this.addEmailOptions({
// Usual vars for email - 2018-02-28
subject: subject,
html_body: bodyHtml || body,
text_body: body,
//for working with version 7.10.[0.1.2]: added to be compatible - 2018-02-28
name: subject,
description_html: bodyHtml || body,
description: body,
// to be solved in the Sidecar Email
//pdf_attachment : {module:'METRO_visites_generale',module_id:this.model.get('id'),name:this.model.get('name')},
//attachments : {module:'METRO_visites_generale',module_id:this.model.get('id'),name:this.model.get('name')},
attachments : {upload_id: document_id, name:filename1, filename: filename1},
//attachments : attachment_pdf
});
},


emailOptionSubject: function() {
var shareParams = this._getShareParams(),
subject = this.shareTplSubject(shareParams),
body = this.shareTplBody(shareParams),
bodyHtml = this.shareTplBodyHtml(shareParams);

//attachment_pdf = app.bwc.buildRoute(this.module,this.model.get('id'),'sugarpdf',{sugarpdf:'visitesgenerale'});

// Generate the PDF and return a document ID
var gateway = 'save_vg_pdf';

filename1 = 'Rapport: ' + this.model.get('name');

var document_id = '';

request = new XMLHttpRequest();

$.ajax({


beforeSend: function (request)
{
request.setRequestHeader("OAuth-Token", SUGAR.App.api.getOAuthToken());
App.alert.show('wait', {
level: 'process',
messages: 'Generation du PDF'
});
},
url: "rest/v10/"+gateway+"/"+this.model.get('id') ,

dataType: "json",
// WAS GET
type: "GET",
async:false,
success: function(doc_id)
{
App.alert.dismissAll();
document_id = doc_id;

},
error: function(){
App.alert.dismissAll();
app.alert.show('server-error',
{
level: 'error',
messages: 'ERR_GENERIC_SERVER_ERROR'
});
}
});

this.addEmailOptions({
// Usual vars for email - 2018-02-28
subject: subject,
html_body: bodyHtml || body,
text_body: body,
//for working with version 7.10.[0.1.2]: added to be compatible - 2018-02-28
name: subject,
description_html: bodyHtml || body,
description: body,
// to be solved in the Sidecar Email
//pdf_attachment : {module:'METRO_visites_generale',module_id:this.model.get('id'),name:this.model.get('name')},
//attachments : {module:'METRO_visites_generale',module_id:this.model.get('id'),name:this.model.get('name')},
attachments : {upload_id: document_id, name:filename1, filename: filename1},
//attachments : attachment_pdf
});



},

})

Outcomes