Skip to content

Commit

Permalink
Merge pull request #6 from helloextend/master
Browse files Browse the repository at this point in the history
sync to master
  • Loading branch information
amillerExtend authored Feb 27, 2024
2 parents bf7595b + 2562883 commit c4aff1c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ define(['N/url',
console.log('stItemId', stItemId);
var stItemName = objCurrentRec.getText({ fieldId: 'custpage_item_select' });
var stItemList = objCurrentRec.getValue({ fieldId: 'custpage_item_list' });
var stConfigRec = objCurrentRec.getValue({ fieldId: 'custpage_config' });
var stLeadToken = objCurrentRec.getValue({ fieldId: 'custpage_lead_input' });
var stItemQty;
var stLineNum;
var stItemRefId;


if (!EXTEND_UTIL.objectIsEmpty(stItemId)) {
var arrItemList = JSON.parse(stItemList);
//var stItemQty = arrItemList.find(x => x.id === stItemId).quantity;
Expand All @@ -111,7 +114,9 @@ define(['N/url',
'arrItemid': stItemList,
'line': stLineNum,
'quantity': stItemQty,
'refid': stItemRefId
'refid': stItemRefId,
'config': stConfigRec,
'leadToken': stLeadToken
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ define([

console.log('Handling Input', context);
// console.log('Sublist', context.currentRecord.getCurrentSublistValue({ sublistId: context.sublistId }));
var stExtendConfigRecId = runtime.getCurrentScript().getParameter('custscript_ext_config_rec_cs');
console.log('config', 'getting.....');
var config = EXTEND_CONFIG.getConfig(1);
var config = EXTEND_CONFIG.getConfig(stExtendConfigRecId);
console.log('config', config);

var refIdValue = config.refId;
Expand Down Expand Up @@ -138,7 +139,7 @@ define([
arrItemList = JSON.stringify(arrItemList);
console.log('arrItemList', arrItemList);

_callSuitelet(arrItemList, stItemId, stItemName, stLineNum, intQty, stItemRefId, JSON.stringify(config));
_callSuitelet(arrItemList, stItemId, stItemName, stLineNum, intQty, stItemRefId, stExtendConfigRecId);

return true;
}
Expand All @@ -155,7 +156,8 @@ define([
});
console.log('linecount', linecount);
console.log('config', 'getting.....');
var config = EXTEND_CONFIG.getConfig(1);
var stExtendConfigRecId = runtime.getCurrentScript().getParameter('custscript_ext_config_rec_cs');
var config = EXTEND_CONFIG.getConfig(stExtendConfigRecId);
console.log('config', config);

var refIdValue = config.refId;
Expand Down Expand Up @@ -183,14 +185,15 @@ define([
line: i
});
// Lookup to item to see if it is eligible for warranty offers
/*
var arrItemLookupField = search.lookupFields({
type: 'item',
id: stItemId,
columns: 'custitem_product_protection_item'
});
var bIsWarranty = arrItemLookupField.custitem_ext_is_warrantable;

log.debug('Is warranty', typeof(bIsWarranty) + ', ' + bIsWarranty);
// var bIsWarranty = arrItemLookupField.custitem_ext_is_warrantable;
*/
// log.debug('Is warranty', typeof(bIsWarranty) + ', ' + bIsWarranty);
if (refIdValue) {
// Lookup to item to see if it is eligible for warranty offers
var arrItemLookup = search.lookupFields({
Expand Down Expand Up @@ -228,16 +231,17 @@ define([
//console.log('objItem', objItem);
//push to array
// If item is not a warranty item, return
if (stExtendItem != stItemId || !bIsWarranty) {
if (stExtendItem != stItemId) {
arrItemList.push(objItem);
}
}
var stArrayItemList = JSON.stringify(arrItemList);
console.log('stArrayItemList', stArrayItemList);
_callSuitelet(stArrayItemList, arrItemList[0].id, arrItemList[0].name, arrItemList[0].line, arrItemList[0].qty, arrItemList[0].refId);
_callSuitelet(stArrayItemList, arrItemList[0].id, arrItemList[0].name, arrItemList[0].line, arrItemList[0].qty, arrItemList[0].refId, stExtendConfigRecId);
}

function _callSuitelet(arrItemList, stItemId, stItemName, stLineNum, stItemQty, stItemRefId, config) {
console.log('config', config);
//Resolve suitelet URL
var slUrl = url.resolveScript({
scriptId: 'customscript_ext_offer_presentation_sl',
Expand All @@ -249,9 +253,11 @@ define([
'line': stLineNum,
'quantity': stItemQty,
'refid': stItemRefId,
'config' : config
'config' : config,
// 'leadToken': stLeadToken
}
});
console.log('slUrl', slUrl);
//Call the pop up suitelet
window.open(slUrl, '_blank', 'screenX=300,screenY=300,width=900,height=500,titlebar=0,status=no,menubar=no,resizable=0,scrollbars=0');

Expand Down
22 changes: 8 additions & 14 deletions src/FileCabinet/SuiteScripts/lib/customscript_ext_config_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define([
SANDBOX: 1,
PRODUCTION: 2
}
exports.getConfig = function () {
exports.getConfig = function (stExtendConfigRecId) {
//Get storeId & APIkey from config custom record

var STORE_ID;
Expand All @@ -25,20 +25,15 @@ define([
var SHIPPING_ITEM;
var DOMAIN = 'https://api-demo.helloextend.com';

// VF need to account for calling from Client and MR Scripts
var currScript= runtime.getCurrentScript();
var stExtendConfigRecId
if(currScript.id == "customscript_ext_so_offer_controller_cs" ){
stExtendConfigRecId = currScript.getParameter('custscript_ext_config_rec_cs');
}else if(currScript.id == "customscript_ext_refund_create_mr" ){
stExtendConfigRecId = currScript.getParameter('custscript_ext_config_record');
}else{
stExtendConfigRecId = currScript.getParameter('custscript_ext_config_rec');
if(!stExtendConfigRecId){
stExtendConfigRecId = runtime.getCurrentScript().getParameter('custscript_ext_configuration_record');
log.audit('stExtendConfigRecId', stExtendConfigRecId);
}
var arrFilters = [];
log.debug('_getConfig: stExtendConfigRecId ', stExtendConfigRecId);

var arrFilters = ["internalId", "is", stExtendConfigRecId];

if(stExtendConfigRecId){
arrFilters.push(["internalId", "is", stExtendConfigRecId]);
}
var customrecord_ext_configurationSearchObj = search.create({
type: "customrecord_ext_configuration",
filters: [
Expand Down Expand Up @@ -72,7 +67,6 @@ define([
default:
DOMAIN = 'https://api-demo.helloextend.com'
};
log.debug('_getConfig: DOMAIN ', DOMAIN);
STORE_ID = result.getValue({ name: 'custrecord_ext_store_id' });
API_KEY = result.getValue({ name: 'custrecord_ext_api_key' });
EMAIL = result.getValue({ name: 'custrecord_ext_demo_email' });
Expand Down
1 change: 1 addition & 0 deletions src/FileCabinet/SuiteScripts/lib/customscript_ext_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ define([
return objAddress;
};
//get Item's reference ID

exports.getItemRefId = function (stItemId, objExtendConfig) {
// var config = EXTEND_CONFIG.getConfig();
var refIdValue = objExtendConfig.refId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ define([
var stItemInternalId = context.request.parameters.itemid;
var stItemRefId = context.request.parameters.refid;
var stLeadToken = context.request.parameters.leadToken;
var config = JSON.parse(context.request.parameters.config);
var stConfigRec = JSON.parse(context.request.parameters.config);
var objConfig = EXTEND_CONFIG.getConfig(stConfigRec);
log.debug('stItemRefId', stItemRefId);
log.debug('stLeadToken', stLeadToken);
log.debug('config ' + typeof config, config);
log.debug('objConfig ' + typeof objConfig, objConfig);


// Create the form
Expand Down Expand Up @@ -376,10 +377,10 @@ define([
if (stItemRefId || stLeadToken) {
try {
if(stLeadToken){
var objResponse = EXTEND_API.getLeadOffers(stLeadToken, config);
var objResponse = EXTEND_API.getLeadOffers(stLeadToken, objConfig);
log.debug('OFFER MODAL SUITELET: Offers JSON Response', objResponse);
}else{
var objResponse = EXTEND_API.getOffers(stItemRefId, config);
var objResponse = EXTEND_API.getOffers(stItemRefId, objConfig);
log.debug('OFFER MODAL SUITELET: Offers JSON Response', objResponse);
}

Expand All @@ -392,8 +393,11 @@ define([
log.debug('OFFER MODAL SUITELET: arrPlans', arrPlans);
if (!arrPlans) {
var arrPlans = objResponseBody.plans.base;
if(!arrPlans){
///show alert no plans for item
}
}

//Populate Sublist Values
for (var i = 0; i < arrPlans.length; i++) {
objPlanList.setSublistValue({
Expand Down

0 comments on commit c4aff1c

Please sign in to comment.