Sciuridae54696d
03/02/2021, 3:13 AMbattk
03/02/2021, 3:14 AMbattk
03/02/2021, 3:14 AMSciuridae54696d
03/02/2021, 3:49 AMbattk
03/02/2021, 4:01 AMbattk
03/02/2021, 4:01 AMbattk
03/02/2021, 4:02 AMbattk
03/02/2021, 4:02 AMbattk
03/02/2021, 4:03 AMmichoel
03/02/2021, 4:10 AMmichoel
03/02/2021, 4:11 AMfunction encodeBase64UrlSafe(object) {
var stringified = JSON.stringify(object);
var base64UrlSafeMap = {
"+": "-",
"/": "_",
"=": "",
};
var encoded = nlapiEncrypt(stringified, "base64");
Object.keys(base64UrlSafeMap).forEach(function (searchValue) {
encoded = encoded.replace(searchValue, base64UrlSafeMap[searchValue]);
});
return encoded;
}
battk
03/02/2021, 4:12 AMmichoel
03/02/2021, 4:12 AMmichoel
03/02/2021, 4:13 AMmichoel
03/02/2021, 4:13 AM/**
* Helper function to decode the script parameters that are passed from the Supplier Invoice User Event Script
* They are passed as stringified JavaScript objects that are Base64 (Url Safe) encoded
*
* @param context script context to read parameters from
* @param {string} parameter name of the url parameter
* @returns {any}
*/
function getBase64EncodedJsonParameter(context, parameter) {
const encoded = context.request.parameters[parameter];
if (!encoded) {
throw error.create({
name: "CARS_REQUIRED_PARAM",
message: `Missing required parameter "${parameter}"`,
});
}
let decoded;
try {
decoded = encode.convert({
inputEncoding: encode.Encoding.BASE_64_URL_SAFE,
outputEncoding: encode.Encoding.UTF_8,
string: encoded,
});
} catch {
throw error.create({
name: "CARS_INVALID_PARAM",
message: `Invalid value for "${parameter}" parameter. Unable to decode from Base64UrlSafe`,
});
}
try {
return JSON.parse(decoded);
} catch {
throw error.create({
name: "CARS_INVALID_PARAM",
message: `Invalid value for "${parameter}" parameter. Unable to parse as JSON`,
});
}
}
stalbert
03/02/2021, 4:25 AMmichoel
03/02/2021, 4:27 AMSelcuk Dogru
03/02/2021, 8:09 AMmichoel
03/02/2021, 9:18 AM