This topic contains 5 replies, has 0 voices, and was last updated by david.smith 7 years, 9 months ago.
-
AuthorPosts
-
January 31, 2017 at 7:41 am #1221
al3xiconHello gurus –
I have a Map/Reduce script to send cancellation emails based off of a saved search. The email is sending just fine, however the
Code:
relatedRecords
object doesn’t seem to work, when using the keyCode:
transactionId
, however when usingCode:
entityId
, it works fine and logs the email under the customer’s Communication -> Messages subtab.Has anybody experienced this before? Any idea if I’m doing something wrong? Here is the entirety of my code, any help or insight is appreciated!
Code:
/**
* @NApiVersion 2.x
* @NScriptType MapReduceScript
* @NModuleScope SameAccount
*/
define([‘N/email’, ‘N/search’, ‘N/render’, ‘N/record’],function(email, search, render, record) {
var department_map = {
15: {
templates: {
1: 301 // RISKIFIED DECLINED (KW)
},
author: 113746, // Customer Care
template_vars: {
‘%SALESCHANNEL%’: ‘KegWorks.com’
}
},
35: {
templates: {
1: 302 // RISKIFIED DECLINED (BTB)
},
author: 21100362, // Customer Care BTB
template_vars: {
‘%SALESCHANNEL%’: ‘BehindtheBar.com’
}
}
};function getInputData() {
return search.load({
id: ‘customsearch_kw_cancelledorderstoemail’
});
}function map(context) {
var searchResult = JSON.parse(context.value);
context.write(searchResult);
}function summarize(summary) {
summary.output.iterator().each(function(res,v) {
res = JSON.parse(res);
var so_id = parseInt(res[‘id’]);
var values = res[‘values’];
var email_address = values[’email’];
var customer = values[‘entity’][‘value’];
var reason = values[‘custbody_kw_cancelemailreason’][‘value’];
var dept = values[‘department’][‘value’];
var storefront_order = values[‘custbody_custbody_storefront_order’];
var document_number = values[‘tranid’];
var first_name = values[‘firstname.customerMain’];
var company_name = values[‘companyname.customerMain’];
var template;if (email_address) {
try {
template = department_map[dept][‘templates’][reason];
} catch (e) {
log.error(‘Error getting template’, ‘Reason or Template doesn’t exist. ‘+
‘Reason: ‘+reason+’, dept: ‘+dept+’, template: ‘+template);
log.error(e);
}if (template) {
var merge = render.mergeEmail({
templateId: template,
transactionId: so_id
});var subject = merge.subject;
var body = merge.body;var date = new Date();
var template_vars = department_map[dept][‘template_vars’];
template_vars[‘%NLORDERNUM%’] = storefront_order ? storefront_order : document_number;
template_vars[‘%NLCUSTNAME%’] = first_name ? first_name : company_name;
template_vars[‘%NLEMAILADDRESS%’] = ‘‘+email_address+’‘;
template_vars[‘%NLCURRYEAR%’] = date.getFullYear();
for (var v in template_vars) {
var regexp = new RegExp(v, ‘g’);
subject = subject.replace(regexp, template_vars[v]);
body = body.replace(regexp, template_vars[v]);
}try {
email.send({
author: department_map[dept][‘author’],
recipients: email_address,
subject: subject,
body: body,
relatedRecords: {
//entityId: customer,
transactionId: so_id
}
});
} catch (e) {
log.error(‘Error sending email’, e);
}try {
record.submitFields({
type: record.Type.SALES_ORDER,
id: so_id,
values: {
custbody_kw_cancelemailsent: true
}
});} catch (e) {
log.error(‘Error updating order ‘+so_id, e);
}}
}
return true;
});
}return {
getInputData: getInputData,
map: map,
summarize: summarize
};});
This is a cached copy. Click here to see the original post. -
January 31, 2017 at 8:41 am #1222
Olivier Gagnon NCAlright so I checked and we have quite a few scripts where we are tagging the transaction. I also checked an account where we have script running and confirmed the email was properly attached to the transactions, so fundamentally that seems to be working.
I will say though that none of these were via a map/reduce, so if it is a specific ma/reduce problem, I wouldn’t have encountered it.
One thing I did see is that in a few of our scripts we wrapped the internal id in a parseInt() – maybe NS is being finicky about your so_id? Try that first maybe, since it’s super quick to try out.
Otherwise, I don’t see what the problem would be.
Edit: Oh, I see you are in fact using parseInt higher up. Well then. I’m out of ideas. I’d say file a case!
-
January 31, 2017 at 8:52 am #1223
al3xiconThanks for the response Olivier Gagnon NC – glad to see I’m not the only stumped one. But, also interesting to note that you have examples of it indeed working. I opened a case with NS last week, and there’s been some back and forth so hopefully I’m close to a resolution on this one, figured I’d reach out here anyway. Cheers!
-
February 7, 2017 at 11:37 am #1224
al3xiconSo, the answer to this was that NS didn’t like reading that parameter as a number. I changed it to:
Code:
so_id.toString()
and it worked just fine. That is very frustrating, and I didn’t see it anywhere in the documentation. -
February 7, 2017 at 11:51 am #1225
al3xiconAlso got this confusing response from support (after they helped me determine the ‘fix’):
Support Case #: 2618341.
Hi Alex,
Thank you for taking my call.
As discussed, the transactionID parameter under relatedRecords options needs to be string for it to work. We have tested this on your end and it was successful.
With regards to the documentation, as per checking, this is not NetSuite documentation defect as it is more of JavaScript native discrepancy over integer and string.
As agreed, I will be closing this case. Should you have any other concerns, feel free to contact NetSuite Customer Support, or open a case for us to assist you.
Regards,
Bianca Reyes
Customer Support โ SuiteCloud Team
NetSuite, Inc.
Not sure I get how this is JavaScript’s fault…
al3xicon replied on 02/07/2017, 12:33 PM: Note that the documentation there actually does indicate that it expects a Number, not a String, for the transactionId parameter.
-
February 7, 2017 at 12:11 pm #1226
david.smithI’ve run into this exact same thing recently. Very frustrating.
al3xicon replied on 02/07/2017, 12:14 PM: Thanks for corroborating, at least.
-
AuthorPosts
You must be logged in to reply to this topic.