/**
* @NApiVersion 2.1
* @NScriptType MapReduceScript
*/
/************************************************************************************************
* * Map/Reduce Script For Sending SO Details to Delivery Dispatcher **
*
*
* **********************************************************************************************
*
* Author: Jobin and Jismi IT Services
*
* Date Created : 26-August-2022
*
* Created By: Athul Krishna, Jobin and Jismi IT Services
*
* Description : Map/Reduce Script For Sending SO Details to Delivery Dispatcher
*
* REVISION HISTORY
*
*
*
*
***********************************************************************************************/
define(['N/config', 'N/record', 'N/runtime', 'N/https','N/search', '../../AHAP-14 Dispatch Track Integration/Library/JJ CM Sales Force API AHAP-14.js', ],
/**
* @param{error} error
* @param{http} http
* @param{record} record
* @param{runtime} runtime
* @param{search} search
* @param{url} url
*/
(config, record, runtime, https,search, dispatchTracker,) => {
/**
* Defines the function that is executed at the beginning of the map/reduce process and generates the input data.
* @param {Object} inputContext
* @param {boolean} inputContext.isRestarted - Indicates whether the current invocation of this function is the first
* invocation (if true, the current invocation is not the first invocation and this function has been restarted)
* @param {Object} inputContext.ObjectRef - Object that references the input data
* @typedef {Object} ObjectRef
* @property {string|number} ObjectRef.id - Internal ID of the record instance that contains the input data
* @property {string} ObjectRef.type - Type of the record instance that contains the input data
* @returns {Array|Object|Search|ObjectRef|File|Query} The input data to use in the map/reduce process
* @since 2015.2
*/
const getInputData = (inputContext) => {
try {
let accessToken = dispatchTracker.serviceOrder.generateAccessToken("sandbox");
log.debug("accessToken",accessToken);
if(accessToken){
record.submitFields({
type: 'customrecord_jj_sales_force_token',
id: 1,
values: {
'custrecord_jj_sales_access_token': accessToken
},
options: {
enableSourcing: false,
ignoreMandatoryFields : true
}
});
}
var url = 'https://stg.api01.haieramericas.net/eip-gea-availability-xapi/api/v1/cachedAvailability';
// Define the request headers
var headers = {
'Client_id': 'b453981705584326b7b29cf7c79ab4ec',
'Client_secret': '9fbc5d99eE1A4C738B0E849198026355',
'Content-Type': 'application/json',
'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik5qVXdNMFUxUVVRM00wSXlNVVZCTUVSQ09EUkJSak00TURnd09UZzBNRGsyUVRNelJUazNPUSJ9.eyJpc3MiOiJodHRwczovL2dlYS1ub25wcm9kLmF1dGgwLmNvbS8iLCJzdWIiOiJCbjF2STlma3V4bkp6ellIVEFnOUZJemVPc0ljcVlpa0BjbGllbnRzIiwiYXVkIjoiZ2VhLWp3dC1hdXRob3JpemVyLW5vbi1wcmQiLCJpYXQiOjE3MTYxODI0OTcsImV4cCI6MTcxNjE4MzM5NywiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwiYXpwIjoiQm4xdkk5Zmt1eG5KenpZSFRBZzlGSXplT3NJY3FZaWsifQ.Gdx0U_ZwG_h8G3_9Kadkml3dByB_j4tg4PCeME0J5UqfnGrp1SROJFLROSmrbnRK7xclIa8YFsrO2iKDOw4Mc57VWGKOTt3f-SPWXFHIhkLwUeaAWB494lAiUu0AOJwiNzAQ353ZQ_249F8NL9iBy8PcCckWQyd-QJprT3VR13_S99Ru0xPhF9-5K1sFt-tePlTjtLzjVmr0QgpAcOxXNWR02IYaWaJyYm8mg07oTGKF4mrmbnIubQroq6ngTQlSmFz6VHJo2MkGhaII_LUFnK7UVtJi1D9NWV2MlPG6QMhXTCeAOpnxgAUr0qJUZ__Pv-EoCbMLfJh18Q6XsSgrCA'
};
// Define the request body
var body = [
{
"inventoryItemName": ["CVM517P4MW2", "AZ91H12E3E"],
"zipcode": "94043",
"orgCode": "LOU"
},
{
"inventoryItemName": ["AZ91H12E3E"],
"zipcode": "40220"
}
];
try {
// Send the HTTP POST request
var response = https.post({
url: url,
body: JSON.stringify([
{
"inventoryItemName": [
"CVM517P4MW2",
"AZ91H12E3E"
],
"zipcode": "94043",
"orgCode": "LOU"
},
{
"inventoryItemName": [
"AZ91H12E3E"
],
"zipcode": "40220"
}
]),
headers: {
'Client_id': 'b453981705584326b7b29cf7c79ab4ec',
'Client_secret': '9fbc5d99eE1A4C738B0E849198026355',
'Content-Type': 'application/json',
'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik5qVXdNMFUxUVVRM00wSXlNVVZCTUVSQ09EUkJSak00TURnd09UZzBNRGsyUVRNelJUazNPUSJ9.eyJpc3MiOiJodHRwczovL2dlYS1ub25wcm9kLmF1dGgwLmNvbS8iLCJzdWIiOiJCbjF2STlma3V4bkp6ellIVEFnOUZJemVPc0ljcVlpa0BjbGllbnRzIiwiYXVkIjoiZ2VhLWp3dC1hdXRob3JpemVyLW5vbi1wcmQiLCJpYXQiOjE3MTYxODI0OTcsImV4cCI6MTcxNjE4MzM5NywiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwiYXpwIjoiQm4xdkk5Zmt1eG5KenpZSFRBZzlGSXplT3NJY3FZaWsifQ.Gdx0U_ZwG_h8G3_9Kadkml3dByB_j4tg4PCeME0J5UqfnGrp1SROJFLROSmrbnRK7xclIa8YFsrO2iKDOw4Mc57VWGKOTt3f-SPWXFHIhkLwUeaAWB494lAiUu0AOJwiNzAQ353ZQ_249F8NL9iBy8PcCckWQyd-QJprT3VR13_S99Ru0xPhF9-5K1sFt-tePlTjtLzjVmr0QgpAcOxXNWR02IYaWaJyYm8mg07oTGKF4mrmbnIubQroq6ngTQlSmFz6VHJo2MkGhaII_LUFnK7UVtJi1D9NWV2MlPG6QMhXTCeAOpnxgAUr0qJUZ__Pv-EoCbMLfJh18Q6XsSgrCA'
}
});
// Log the response body
log.debug('Response Body:', response.body);
} catch (e) {
// Handle any errors
log.error('Error:', e.message);
}
log.debug("response",response)
return [];
} catch (e) {
log.error("error@getInput", e);
return [];
}
}
/**
* Defines the function that is executed when the map entry point is triggered. This entry point is triggered automatically
* when the associated getInputData stage is complete. This function is applied to each key-value pair in the provided
* context.
* @param {Object} mapContext - Data collection containing the key-value pairs to process in the map stage. This parameter
* is provided automatically based on the results of the getInputData stage.
* @param {Iterator} mapContext.errors - Serialized errors that were thrown during previous attempts to execute the map
* function on the current key-value pair
* @param {number} mapContext.executionNo - Number of times the map function has been executed on the current key-value
* pair
* @param {boolean} mapContext.isRestarted - Indicates whether the current invocation of this function is the first
* invocation (if true, the current invocation is not the first invocation and this function has been restarted)
* @param {string} mapContext.key - Key to be processed during the map stage
* @param {string} mapContext.value - Value to be processed during the map stage
* @since 2015.2
*/
// const map = (mapContext) => {
// }
function checkForParameter(parameter) {
if (parameter !== "" && parameter !== null && parameter !== undefined && parameter !== false && parameter !== "null"
&& parameter !== "undefined" && parameter !== " " && parameter !== 'false') {
return true;
} else {
log.debug("empty")
return false;
}
}
/**
* Defines the function that is executed when the reduce entry point is triggered. This entry point is triggered
* automatically when the associated map stage is complete. This function is applied to each group in the provided context.
* @param {Object} reduceContext - Data collection containing the groups to process in the reduce stage. This parameter is
* provided automatically based on the results of the map stage.
* @param {Iterator} reduceContext.errors - Serialized errors that were thrown during previous attempts to execute the
* reduce function on the current group
* @param {number} reduceContext.executionNo - Number of times the reduce function has been executed on the current group
* @param {boolean} reduceContext.isRestarted - Indicates whether the current invocation of this function is the first
* invocation (if true, the current invocation is not the first invocation and this function has been restarted)
* @param {string} reduceContext.key - Key to be processed during the reduce stage
* @param {List<String>} reduceContext.values - All values associated with a unique key that was passed to the reduce stage
* for processing
* @since 2015.2
*/
const reduce = (reduceContext) => {
try {
} catch (e) {
log.debug("error@Reduce", e)
}
}
/**
* Defines the function that is executed when the summarize entry point is triggered. This entry point is triggered
* automatically when the associated reduce stage is complete. This function is applied to the entire result set.
* @param {Object} summaryContext - Statistics about the execution of a map/reduce script
* @param {number} summaryContext.concurrency - Maximum concurrency number when executing parallel tasks for the map/reduce
* script
* @param {Date} summaryContext.dateCreated - The date and time when the map/reduce script began running
* @param {boolean} summaryContext.isRestarted - Indicates whether the current invocation of this function is the first
* invocation (if true, the current invocation is not the first invocation and this function has been restarted)
* @param {Iterator} summaryContext.output - Serialized keys and values that were saved as output during the reduce stage
* @param {number} summaryContext.seconds - Total seconds elapsed when running the map/reduce script
* @param {number} summaryContext.usage - Total number of governance usage units consumed when running the map/reduce
* script
* @param {number} summaryContext.yields - Total number of yields when running the map/reduce script
* @param {Object} summaryContext.inputSummary - Statistics about the input stage
* @param {Object} summaryContext.mapSummary - Statistics about the map stage
* @param {Object} summaryContext.reduceSummary - Statistics about the reduce stage
* @since 2015.2
*/
const summarize = (summaryContext) => {
}
return {getInputData,reduce, summarize}
});