Livio
07/17/2024, 2:03 PMAnthony OConnor
07/17/2024, 2:18 PMLivio
07/17/2024, 2:19 PMAnthony OConnor
07/17/2024, 2:19 PMLivio
07/17/2024, 2:19 PMLivio
07/17/2024, 2:20 PMAnthony OConnor
07/17/2024, 2:21 PMAnthony OConnor
07/17/2024, 2:21 PMLivio
07/17/2024, 2:22 PM/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/ui/serverWidget', 'N/record', 'N/redirect', 'N/search', 'N/runtime'],
function(serverWidget, record, redirect, search, runtime) {
function onRequest(context) {
if (context.request.method === 'GET') {
var form = serverWidget.createForm({ title: 'Email Preferences' });
// Adding field group
form.addFieldGroup({
id: 'main_info',
label: 'Main Information'
});
form.addFieldGroup({
id: 'preferences',
label: 'Preferences'
});
// Email field
var emailField = form.addField({
id: 'custpage_email',
type: serverWidget.FieldType.EMAIL,
label: 'Email Address',
container: 'main_info'
});
emailField.isMandatory = true;
// Preferred Manufacturers field
var manufacturerField = form.addField({
id: 'custpage_preferred_manufacturer',
type: serverWidget.FieldType.MULTISELECT,
label: 'Preferred Manufacturers',
source: 'customlist1', // custom list id
container: 'preferences'
});
manufacturerField.isMandatory = true;
// Email Frequency field
var frequencyField = form.addField({
id: 'custpage_email_frequency',
type: serverWidget.FieldType.SELECT,
label: 'Email Frequency',
source: 'customlist_daily_inventory_list_option', // custom list id
container: 'preferences'
});
frequencyField.isMandatory = true;
form.addSubmitButton({ label: 'Submit' });
context.response.writePage(form);
} else {
var email = context.request.parameters.custpage_email;
var preferredManufacturers = context.request.parameters.custpage_preferred_manufacturer;
var emailFrequency = context.request.parameters.custpage_email_frequency;
// Parse the preferred manufacturers into an array
var preferredManufacturersArray = preferredManufacturers ? preferredManufacturers.split(',') : [];
// Search for the contact with the given email address
var contactSearch = search.create({
type: search.Type.CONTACT,
filters: [
['email', <http://search.Operator.IS|search.Operator.IS>, email]
],
columns: ['internalid']
});
var contactId;
contactSearch.run().each(function(result) {
contactId = result.getValue('internalid');
return false; // Exit loop after finding the first match
});
if (contactId) {
// Load and update the contact record
var contactRecord = record.load({
type: record.Type.CONTACT,
id: contactId
});
contactRecord.setValue({
fieldId: 'custentity_preferred_manufacturer_email',
value: preferredManufacturersArray
});
contactRecord.setValue({
fieldId: 'custentity_daily_inventory_list_email',
value: emailFrequency
});
contactRecord.save();
context.response.write('Preferences updated successfully.');
} else {
context.response.write('No contact found with the provided email address.');
}
}
}
return {
onRequest: onRequest
};
});
Livio
07/17/2024, 2:23 PMAnthony OConnor
07/17/2024, 2:24 PMAnthony OConnor
07/17/2024, 2:25 PMLivio
07/17/2024, 2:25 PMAnthony OConnor
07/17/2024, 2:25 PMLivio
07/17/2024, 2:25 PMAnthony OConnor
07/17/2024, 2:30 PMAnthony OConnor
07/17/2024, 2:32 PMAnthony OConnor
07/17/2024, 2:33 PMAnthony OConnor
07/17/2024, 2:35 PMif GET
return "<html><head></head><body><p>hello world</p></body></html>"
or something? idk if it needs to be a string, been a whileAnthony OConnor
07/17/2024, 2:36 PMLivio
07/17/2024, 2:38 PMLivio
07/17/2024, 2:40 PMEric Schultz
07/17/2024, 2:41 PMLivio
07/17/2024, 2:42 PMAnthony OConnor
07/17/2024, 2:46 PMAnthony OConnor
07/17/2024, 2:48 PMLivio
07/17/2024, 2:48 PMAnthony OConnor
07/17/2024, 2:49 PMLivio
07/17/2024, 2:50 PMAnthony OConnor
07/17/2024, 2:50 PMLivio
07/17/2024, 2:51 PMLivio
07/17/2024, 2:51 PMAnthony OConnor
07/17/2024, 2:51 PMLivio
07/17/2024, 2:52 PMAnthony OConnor
07/17/2024, 2:52 PMLivio
07/17/2024, 2:52 PMLivio
07/17/2024, 2:53 PM