Hi.
I have a function node with code which works as it should. But our team member wants an calculation based on what it seems to be 2 string. Is this possible to do and at the same time output it again as the string (since the api request need this when using the output as invoice rows?)
you can see in the line . This outputs f.eks. 10 / 2 , instead of the answer 5 which we wants.
// hjelpefunksjon for xml-entiteter
const escapeXml = (unsafe) =>
unsafe.replace(/[<>&'"]/g, (c) => &${({ '<': 'lt', '>': 'gt', '&': 'amp', '\'': 'apos', '"': 'quot' })[c]};
);
// sorter input i kunder og id-er for produkter
const lookupId = {};
const customers = [];
for (const item of $input.all()) {
if (item.json.Charges) {
customers.push(item);
} else if (item.json.Id && item.json.No) {
lookupId[item.json.No] = item.json.Id;
}
}
// Lag XML for ordrelinjer
for (const customer of customers) {
customer.json.chargeXml = ‘’;
customer.json.Charges.forEach((charge) => {
customer.json.chargeXml +=
<InvoiceRow> <ProductId>${lookupId[charge.MaterialNumber] ? lookupId[charge.MaterialNumber] : charge.MaterialNumber}</ProductId> <Price>${charge.CorrectSales} / ${charge.UDRCValue}</Price> <InPrice>${charge.CorrectCosts}</InPrice> <Quantity>${charge.UDRCValue}</Quantity> <Name>${escapeXml(charge.PriceableItemDescription)}</Name> </InvoiceRow>
;
});
}
return customers;