Watz
11/05/2024, 8:46 PMWatz
11/05/2024, 8:47 PMconst getInputData = (): { type: string, query: string } => {
log.debug('getInput', 'start')
const suiteQL = getInputDataQuery()
log.debug('getInput', { suiteQL })
const timeStart = new Date().getTime()
const results = query.runSuiteQL({ query: suiteQL }).asMappedResults()
log.debug('result', { resultLength: results.length, time: new Date().getTime() - timeStart, firstFiveResults: results.slice(0, 5) })
return {
type: 'suiteql',
query: suiteQL,
}
}
I've added running the query in getInputData just to verify that it is actually working and has results.
The log is:
{
resultLength: 1133,
time: 545,
firstFiveResults: [
{
id: 3700,
new_eur_amount: 852.54
},
{
id: 4631,
new_eur_amount: 423.05
},
{
id: 4632,
new_eur_amount: 337.9
},
{
id: 4630,
new_eur_amount: 142
},
{
id: 4634,
new_eur_amount: 230.32
}
]
}
The query is a bit "special" with a CTE, but it is working and producing results without nulls
WITH max_rate as (
SELECT
baseCurrency,
transactionCurrency,
MAX(effectiveDate) as effective_date
FROM
currencyRate
WHERE
effectiveDate <= sysdate
GROUP BY
baseCurrency,
transactionCurrency
),
fx_rates as (
SELECT
fx.baseCurrency,
fx.transactioncurrency,
fx.exchangeRate,
fx.effectiveDate
FROM
currencyRate fx
JOIN max_rate ON max_rate.baseCurrency = fx.baseCurrency
AND max_rate.transactionCurrency = fx.transactionCurrency
AND max_rate.effective_date = fx.effectivedate
)
SELECT
REXP.id,
round(
fx_rates.exchangeRate * REXP.custrecord_rexp_rech_expense_org_am,
2
) as new_eur_amount
FROM
customrecord_rexp_rech_expense REXP
JOIN customlist_rexp_rech_exp_stages STAGE on STAGE.id = REXP.custrecord_rexp_rech_expense_stage
JOIN fx_rates on fx_rates.baseCurrency = 1
AND fx_rates.transactioncurrency = REXP.custrecord_rexp_rech_expense_curr
WHERE
lower(STAGE.scriptid) IN('ready_to_be_recharged', 'partially_invoiced')
AND round(
nvl(REXP.custrecord_rexp_rech_expense_eur_amt, 0),
2
) <> round(
fx_rates.exchangeRate * REXP.custrecord_rexp_rech_expense_org_am,
2
)
ericl
11/05/2024, 8:50 PMWatz
11/05/2024, 8:51 PM//greg
11/06/2024, 1:55 AMreturn results
instead of
return {
type: 'suiteql',
query: suiteQL,
}
Watz
11/06/2024, 12:58 PMWatz
11/06/2024, 12:59 PM