Hi I am using this code to integrate Currency lay...
# integrations
h
Hi I am using this code to integrate Currency layer exchange rateprovider with Netsuite /** * @NApiVersion 2.x * @NScriptType ScheduledScript * @NModuleScope SameAccount */ define(['N/https', 'N/record'], function (https, record) { // Define your Currency Layer API access key var apiKey = 'your_api_key'; function updateExchangeRates() { // Define the URL of Currency Layer API var apiUrl = 'https://api.currencylayer.com/live?access_key=' + apiKey; try { // Fetch latest exchange rates from the Currency Layer API var response = https.get({ url: apiUrl }); if (response.body) { var ratesData = JSON.parse(response.body); // Check if rates are available in the response if (ratesData.success && ratesData.quotes) { var quotes = ratesData.quotes; // Loop through the quotes to update exchange rates in NetSuite for (var quote in quotes) { if (quotes.hasOwnProperty(quote)) { var currencyCode = quote.substring(3); // Extract currency code from quote (e.g., USDEUR) var exchangeRate = quotes[quote]; // Create or update exchange rate record in NetSuite var exchangeRateRecord = record.create({ type: record.Type.CURRENCY_RATE }); exchangeRateRecord.setValue({ fieldId: 'basecurrency', value: 'USD' // Set your base currency here }); exchangeRateRecord.setValue({ fieldId: 'currencymatch', value: 'M' // Set to M for market rate }); exchangeRateRecord.setValue({ fieldId: 'exchangerate', value: exchangeRate }); exchangeRateRecord.setValue({ fieldId: 'currency', value: currencyCode }); exchangeRateRecord.save(); } } } else { log.error({ title: 'Error Fetching Exchange Rates', details: ratesData.error.info }); } } } catch (error) { log.error({ title: 'Error Updating Exchange Rates', details: error }); } } return { execute: updateExchangeRates }; }); ReferenceError: "search" is not defined. This error occurred. could you please help me to resolve this.
b
It looks like you're trying to use the search module without importing it. Try updating to this:
Copy code
define(['N/https', 'N/record', 'N/search'], function (https, record, search)
p
weird part is that it isn't declared/used in the script, blinkingguy
confused dog 1
h
I have to parse the fetched currency rates under lists > accounting > currency exchange rate. Can anybody help me with the suitscript 2.0 code.
n
Maybe use the n/currency module if all you need is the exchange rate between 2 currencies for a given date? currency.exchangeRate(options)