When customer fill the review form and submite , the customer will get email for the review for the email the customer have registered use the below js and suitescript
Javascript :
define(
'JJ.reviewmail.review'
, [
'ProductReviews.Form.View',
'Backbone.FormView',
'ProductReviews.FormConfirmation.View',
'Utils'
]
/* function is declared with multiple parameters,
which represent the dependencies or modules being
injected into the function*/
, function (
reviewView,
ProductReviewsFormView,
BackboneFormView,
ProductReviewsFormConfirmationView,
Utils
)
{
'use strict';
return {
mountToApp: function mountToApp (container)
{
/** @type {LayoutComponent} */
var layout = container.getComponent('Layout');
_.extend(ProductReviewsFormView.prototype, {
events: _.extend({}, ProductReviewsFormView.prototype.events,{
'submit form': 'customSaveForm',
}),
customSaveForm: function(e) {
e && e.preventDefault();
this.prepareItem();
this.model.set('itemid', this.item.get('internalid'));
/* use id as selector because rating's div doesn't have name.
This selector is used to show validations' errors */
this.selector = 'id';
const promise = BackboneFormView.saveForm.apply(this, arguments);
const self = this;
let object = self.model.attributes;
console.log('Objects', object);
var url = Utils.getAbsoluteUrl(getExtensionAssetsPath("services/review.Service.ss"))
$.post(url, JSON.stringify(object))
.done(function (data) {
if (data != "undefined") {
const preview_review = new ProductReviewsFormConfirmationView({
model: self.model,
product: self.product,
application: self.application
});
preview_review.showContent();
}
else{
alert('Please Login to Submit Reviews.')
}
}
);
self.render();
},
});
}
};
});
suitescript
define('JJ.reviewmail.review'
, [
'ProductReviews.Model',
'SC.Model',
'SC.Models.Init',
'Application',
'Utils',
'Configuration',
'underscore'
]
/* function is declared with multiple parameters,
which represent the dependencies or modules being
injected into the function*/
, function (
ProductReviewsModel,
SCModel,
ModelsInit,
Application,
Utils,
Configuration,
_
) {
'use strict';
return SCModel.extend({
/* The create function is called when creating a new review.
It takes a data parameter, which likely contains the data for
the review being created*/
create: function (data) {
try {
if (this.loginRequired && !ModelsInit.session.isLoggedIn2()) {
throw unauthorizedError;
}
const review = nlapiCreateRecord('customrecord_ns_pr_review')
if (ModelsInit.session.isLoggedIn2()) {
review.setFieldValue('custrecord_ns_prr_writer', nlapiGetUser() + '');
}
if (data.writer) {
data.writer.name &&
review.setFieldValue(
'custrecord_ns_prr_writer_name',
Utils.sanitizeString(data.writer.name)
);
data.writer.id && review.setFieldValue('custrecord_ns_prr_writer', data.writer.id);
}
data.rating && review.setFieldValue('custrecord_ns_prr_rating', data.rating);
data.title && review.setFieldValue('name', Utils.sanitizeString(data.title));
if (data.text) {
const sanitized_text = Utils.sanitizeString(data.text);
review.setFieldValue('custrecord_ns_prr_text', sanitized_text);
data.text = sanitized_text.replace(/\n/g, '<br>');
}
data.itemid && review.setFieldValue('custrecord_ns_prr_item_id', data.itemid);
const review_id = nlapiSubmitRecord(review);
data.review_id = review_id;
_.each(data.rating_per_attribute, function (rating, name) {
const review_attribute = nlapiCreateRecord('customrecord_ns_pr_attribute_rating');
review_attribute.setFieldValue('custrecord_ns_prar_item', data.itemid);
review_attribute.setFieldValue('custrecord_ns_prar_review', review_id);
review_attribute.setFieldValue('custrecord_ns_prar_rating', rating);
review_attribute.setFieldText('custrecord_ns_prar_attribute', name);
nlapiSubmitRecord(review_attribute);
});
var positiveEmailContents = "Hello " + data.writerName + ",\n Thank you for your valuable feedback. \n We are thrilled that the Product suits your needs. We take great pride in our work, and our sincerest hope is that it helps each one of our customers accomplish their goals. Your feedback has demonstrated that it does, and we appreciate you letting us know.";
var negativeEmailContents ="Hello " + data.writerName +", \n Thank you for your valuable feedback.\n We’re so sorry that the service you purchased was not completed in a manner. We take great pride in our work, and our hope is always that it each one of our customers accomplish their goals. Clearly this was no experience, and we apologize.";
if (parseInt(data.rating) >=3) {
var emailSend = nlapiSendEmail(4, 'support@contactus.com', "About the Ratings you'r submitted.", positiveEmailContents, null, null, null, null);
} else {
var emailSend = nlapiSendEmail(4,'support@contactus.com', "About the Ratings you'r submitted.", negativeEmailContents, null, null, null, null);
}
data.emailSend = emailSend;
return data;
}
catch (error) {
console.error('Error @create', error);
}
}
});
});