I’m attempting to get Zapier to transform inputData from a PayPal transaction from decimal to hexadecimal. Although the information is retrieved, the output remains in decimal format. Here’s what I’ve tried:
return {
hexValue: Number(inputData.amountValue.toString(16))
};
The inputData.amountValue is taken from a number entered by the user in a PayPal transaction. When I hardcode a numeric value instead of using inputData.amountValue, the code functions correctly, yielding a hex output.
I also tested the following version with no changes in outcome, using hexValue instead of amountValue:
var transactionValue = inputData.hexValue;
var hexOutcome = transactionValue.toString(16);
output = {convertedHex: hexOutcome};
Could someone guide me on how to achieve the desired conversion?
It seems the issue might be that the type of inputData.amountValue isn’t being handled correctly as a number before conversion. Ensure that inputData.amountValue is parsed as an integer before converting it to a hexadecimal string. You might consider using parseInt() to enforce this conversion, as follows:
var transactionValue = parseInt(inputData.amountValue);
var hexOutcome = transactionValue.toString(16);
output = {convertedHex: hexOutcome};
Make sure your inputData.amountValue is indeed a numeric string or numeric type; otherwise, parseInt() will return NaN. This should provide you with a reliable conversion to hexadecimal if the input data is indeed numeric.
I recall having a similar issue, and it turned out to be related to the way Zapier handles the incoming data types. Make sure that the input data you are working with is not being treated as a floating-point number. A small tweak which sometimes helps is explicitly converting the number to an integer before passing it around. Try using Math.floor() on your amountValue if you’re getting fractional amounts, which might interfere with parseInt(). After that, do the conversion:
var transactionValue = Math.floor(inputData.amountValue);
var hexOutcome = transactionValue.toString(16);
output = {convertedHex: hexOutcome};
Ensure that the amountValue is in a form conducive to conversion by integer operations before applying the toString method with a radix of 16.