wes_w
01/08/2019, 5:08 PMfunction onRequest(context) {
log.audit("Context Request Method",context.request.method);
var params = context.request.parameters;
log.debug("Context Request Parameters",params);
log.debug("Context Response",context.response);
log.debug("Context Headers",context.request.headers);
if (context.request.method === 'GET') {
//If not called by button on item record
if (!params.custom_id || !params.custom_type) {
var form = ui.createForm({
title: 'Update Web Descriptions'
});
var custom_class = form.addField({
id: 'custpage_class'
,type: ui.FieldType.SELECT
,label: 'Template Class'
});
custom_class.addSelectOption({
value: '-'
,text: 'Pick One'
});
var custom_brand = form.addField({
id: 'custpage_brand'
,type: ui.FieldType.SELECT
,label: 'Class Brand'
});
custom_brand.addSelectOption({
value: '-'
,text: 'Pick One'
});
var custom_series = form.addField({
id: 'custpage_series'
,type: ui.FieldType.SELECT
,label: 'Printer Series'
});
custom_series.addSelectOption({
value: '-'
,text: 'Pick One'
});
//Get the classes that have templates (returns array of objects: {internalId: x,name: 'Class Name'}
var templatesWithClasses = getTemplatesWithClasses();
templatesWithClasses.forEach(function (obj) {
custom_class.addSelectOption({
value: obj.internalId,
text: obj.name
});
});
//getBrandsbyClass
var brandsByClass = getBrandsByClass(templatesWithClasses); //{'classid':[{'brandId':brandId,'brandName':brandName},{'brandId2':brandId2,'brandName2':brandName2}]}
log.debug('brands by class',brandsByClass);
var custom_brandsByClass = form.addField({
id: 'custpage_brandsbyclass'
,type: ui.FieldType.LONGTEXT
,label: 'Brands by Class JSON'
});
custom_brandsByClass.defaultValue = brandsByClass;
custom_brandsByClass.updateDisplayType({
displayType: ui.FieldDisplayType.HIDDEN
});
var seriesByClassBrand = getSeriesByClassBrand(templatesWithClasses);
var custom_seriesByClassBrand = form.addField({
id: 'custpage_seriesbyclassbrand'
,type: ui.FieldType.LONGTEXT
,label: 'Series by Class|Brand JSON'
});
custom_seriesByClassBrand.defaultValue = seriesByClassBrand;
custom_seriesByClassBrand.updateDisplayType({
displayType: ui.FieldDisplayType.HIDDEN
});
form.clientScriptModulePath = 'SuiteScripts/Webstore Descriptions/job_uwd_select_client.js';
form.addSubmitButton({
label: 'Submit'
});
form.addResetButton({
label: 'Reset'
});
context.response.writePage(form);
}
else {
//Called by button on item record
// params = type/id
updateDescription(context,params);
}
}
//Called by POST (button on Suitelet form)
// params = class/brand/series
else {
context.response.write(JSON.stringify(params));
log.debug('POST',params);
//Do other stuff
}
}