I hope you are well. I have my user event script to create custom button on netsuite message record. I have client script to refresh the page on button click. I am able to get selected template value in client script before and after refreshing the page but not able to set selected template on custom field (or any field) of message record.I So I want to pass selected template Id from client script to user event script and set in user event before load.
Thanks in advance!
//User Event BeforeLoad
function beforeLoad(scriptContext) {
try {
if (scriptContext.type === 'create') {
var form = scriptContext.form;
var field = form.addField({
id : 'custpage_abc_text',
type : serverWidget.FieldType.TEXT,
label : 'Custom Template Id'
});
form.addButton({
id: 'custpage_email_message_button',
label: 'Refresh',
functionName: 'clientButtonClick'
});
form.clientScriptModulePath = 'SuiteScripts/cs_get_template.js';
form.addButton({
id: 'custpage_email_message_button',
label: 'Refresh',
functionName: 'clientButtonClick'
});
var templateId = rec.getValue({
fieldId: 'custpage_abc_text',
});
log.debug("templateId",templateId);
if(templateId == 272)
{
//Set few sublists
}
}
} catch (e) {
log.error({ title: 'Error Details', details: e });
}
}
//Client Script
function clientButtonClick() {
try {
var currentRec = currentRecord.get();
var templateId = currentRec.getValue({fieldId:"template"})
alert("templateId before refresh"+templateId);
window.onbeforeunload = null;
window.location.href = window.location.href;
var templateId = currentRec.getValue({fieldId:"template"})
alert("templateId after refresh"+templateId);
} catch (e) {
log.error("error in clientButtonClick()",e);
}
}
function pageInit() {
// Initialization code
}