Create a suitelet to get the customer id from website and to get if the checkbox is checked or not and if it is checked then the value of shipping method field, if not checked set the shipping method as UPS . After that send result as object.
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
* @Description
* To show customer based ship method in website
*/
/*******************************************************************************
*
********PCIN-1040**********
*
*
* AUTHOR:JOBIN AND JISMI IT SERVICES LLP
*
* CREATED ON :16/03/2023
*
*
* REVISION HISTORY
*
* Revision 1.0 $ 16/03/2023
*
******************************************************************************/
var instock='false';
var itemobj = [];
define(['N/error', 'N/record', 'N/search'],
/**
* @param {error} error
* @param {record} record
* @param {search} search
*/
function(error, record, search) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
@Since 2015.2 **/
var main = {
onRequest: function(context) {
try {
var customerID = context.request.parameters.customerid;
var callBackFuncStr = context.request.parameters.callback;
log.debug("callBackFuncStr", callBackFuncStr);
log.debug("customerID:", customerID);
//out of stock
try {
var customRecord = record.load({
type: record.Type.CUSTOMER,
id: customerID,
isDynamic: true
});
var shipMethod = customRecord.getValue({
fieldId: 'custentity_jj_customer_based_ship_method'
});
log.debug("shipMethod", shipMethod);
var shippingItem = customRecord.getText({
fieldId: 'shippingitem'
});
var shipItemid = customRecord.getValue({
fieldId: 'shippingitem'
});
if(shippingItem == ""){
shippingItem = "UPS";
}
log.debug("shippingItem", shippingItem);
if(shipMethod== true){
shipItem=shippingItem;
}
else{
shipItem="UPS";
}
itemobj.push({
shipMethod: shipMethod,
shipItem: shipItem,
shipItemid:shipItemid
})
} catch (e) {
log.debug("backordered error", e)
}
var strJson = callBackFuncStr + '(\'' + JSON.stringify(itemobj) + '\')';
context.response.write(strJson);
log.debug("strJson",strJson)
}
catch (e) {
// logme('err@callback', e);
result = false;
var strJson = callBackFuncStr + '(\'' + JSON.stringify({ result: result }) + '\')';
context.response.write(strJson);
}
}
};
for (var key in main) {
if (typeof main[key] === 'function') {
main[key] = trycatch(main[key], key);
}
}
function trycatch(myfunction, key) {
return function() {
try {
return myfunction.apply(this, arguments);
} catch (e) {
log.debug("e in " + key, e);
NOERROR = false;
}
}
};
return main;
});
/*******************************************************************************
* Log these data
*
* @param title
* @param details
* @returns
*/
function logme(title, details) {
log.debug({
title: title,
details: details
});
}