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.