To load a customer record created a suitelet
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/record', 'N/log', 'N/search'], function(record, log, search) {
function onRequest(context) {
var customerId = context.request.body;
log.debug('Customer ID', customerId);
try {
var micrositeTagData = search.lookupFields({
type: record.Type.CUSTOMER,
id: customerId,
columns: ['custentity_tag_microsite']
});
var micrositeTag = micrositeTagData.custentity_tag_microsite[0].value;
log.debug('Microsite Tag Value', micrositeTag);
context.response.write(micrositeTag || 'No microsite tag value found.');
} catch (error) {
log.error('Error accessing customer record', error);
context.response.write("Error accessing customer record: " + error.message);
}
}
return {
onRequest: onRequest
};
});
Color logo style list is updating in the ssles order while adding items to cart
function validateFormsChecksItem() {
var micrositeId;
var totalQty = nlapiGetLineItemCount('item'),
line;
nlapiLogExecution('DEBUG', 'Validate Forms Checks Item', totalQty);
var logoOptionsToConfigure = 0;
var logoOptionsToCreate = [];
try {
var domain = nlapiGetFieldValue('custbody_tag_microsite');
nlapiLogExecution('ERROR', 'Validate Forms domain domain1', domain);
} catch (error) {
nlapiLogExecution('DEBUG', 'Validate Forms error', error);
}
try {
var customerId = nlapiGetFieldValue('entity');
var url = nlapiResolveURL("SUITELET", "customscript_jj_suitelet_scriptable_cart", "customdeploy1", true);
var response = nlapiRequestURL(url, customerId, null, "POST");
var responseCode = parseInt(response.getCode(), 10);
if (responseCode === 200 || responseCode === 302) {
var responseBody = response.getBody();
micrositeId = responseBody;
nlapiLogExecution('DEBUG', 'micrositeId 1234', micrositeId);
}
} catch (error) {
nlapiLogExecution('DEBUG', 'Error retrieving customer record', error);
}
for (line = 1; line <= totalQty; line++) {
var hasLogoOption = nlapiGetLineItemValue('item', 'custcol_tag_logo_option', line) || nlapiGetLineItemValue('item', 'custcol_ag_logooptionselectbox', line);
var hasLogoOptionNonLiquidPixel = nlapiGetLineItemValue('item', 'custcol_tag_logo_option', line);
if (domain == '98' || domain == '94' || domain == '96' || true) {
hasLogoOption = nlapiGetLineItemValue('item', 'custcol_ag_companypersonlizationcolor', line) != '1' || nlapiGetLineItemValue('item', 'custcol_ag_logooptionselectbox', line);
}
nlapiLogExecution('DEBUG', 'hasLogoOption', hasLogoOption);
var item = nlapiGetLineItemValue('item', 'item', line);
try {
if (micrositeId === '2') {
nlapiSelectLineItem('item', line);
if (hasLogoOption === '3' || hasLogoOptionNonLiquidPixel === '3') {
nlapiSetCurrentLineItemValue('item', 'custcol_ag_logostyle', 1);
} else if (hasLogoOption === '5' || hasLogoOptionNonLiquidPixel === '5') {
nlapiSetCurrentLineItemValue('item', 'custcol_ag_logostyle', 2);
} else if (hasLogoOption === '6') {
nlapiSetCurrentLineItemValue('item', 'custcol_ag_logostyle', 1);
} else if (hasLogoOptionNonLiquidPixel === '2') {
nlapiSetCurrentLineItemValue('item', 'custcol_ag_logostyle', 2);
} else if (hasLogoOptionNonLiquidPixel === '4') {
nlapiSetCurrentLineItemValue('item', 'custcol_ag_logostyle', 1);
}
nlapiCommitLineItem('item');
}
} catch (error) {
nlapiLogExecution('DEBUG', 'error in logo style list ', error);
}
if (hasLogoOption) {
var logoOptionItem = nlapiGetLineItemValue('item', 'custcol_tag_logo_option_item', line);
logoOptionsToCreate.push({ item: item, logoOptionItem: logoOptionItem });
logoOptionsToConfigure++;
}
}
nlapiLogExecution('DEBUG', 'logoOptionsToConfigure', logoOptionsToConfigure);
if (logoOptionsToConfigure > 0) {
var values = logoOptionsToCreate;
var counts = {};
values.forEach(function (v) {
if (counts[v.logoOptionItem]) { counts[v.logoOptionItem]++; }
else counts[v.logoOptionItem] = 1;
});
for (var index in counts) {
var quantity = counts[index];
var item = index;
if (item && quantity) {
addLogoOptionsItem(item, quantity);
}
}
}
}