英文:
Using Luxon.js within NetSuite Server Side Scripts
问题
我已经成功在NetSuite客户端脚本中多次使用Luxon。
是否可以在服务器端脚本中使用它?
我已尝试使用与客户端脚本相同的命名约定:
define(['N/https', './luxon'], (https) => {
const beforeLoad(ctx) {
let DateTime = luxon.DateTime;
let Duration = luxon.Duration;
let today = DateTime.now()
}
etc....
}
库可以被正常找到,但每当我声明 let today = DateTime.now()
时,总是收到以下错误信息:
"error": {
"name": "ReferenceError",
"message": "Intl is not defined",
"stack": "ReferenceError: Intl is not defined
at systemLocale (/SuiteScripts/luxon.js:963:28)
at Function.create (/SuiteScripts/luxon.js:...:65)
at new DateTime (/SuiteScripts/luxon.js:...:39)
at Function.now (/SuiteScripts/luxon.js:...:14)
at Object.onRequest (/SuiteScripts/suitelet.js:...:39)"
}
我认为这是因为它未在浏览器中调用。
我希望它能返回服务器时区的对象。
英文:
I've successfully used Luxon many times within NetSuite client scripts.
Is there a way to use it within server-side scripts?
I've tried with the same naming convention as client script
define(['N/https', './luxon'], (https) => {
const beforeLoad(ctx) {
let DateTime = luxon.DateTime;
let Duration = luxon.Duration;
let today = DateTime.now()
}
etc....
}
The library is found with no issue, but always get the following when I declare let today = DateTime.now()
"error": {
"name": "ReferenceError",
"message": "Intl is not defined",
"stack": "ReferenceError: Intl is not defined
at systemLocale (/SuiteScripts/luxon.js:963:28)
at Function.create (/SuiteScripts/luxon.js:...:65)
at new DateTime (/SuiteScripts/luxon.js:...:39)
at Function.now (/SuiteScripts/luxon.js:...:14)
at Object.onRequest (/SuiteScripts/suitelet.js:...:39)"
}
I'm assuming this is because it's not called within a browser.
I was hoping it would return the object in the timezone of the server.
答案1
得分: 1
以下是翻译好的部分:
"在我发布上面的帖子后,我搜索了一下,找到了一个答案:
globalThis.Intl = {
DateTimeFormat: function() {
this.resolvedOptions = function(){
return {
locale: "en-US"
}
}
}
}
在onRequest
函数的开头声明了这个,现在它可以工作了。"
英文:
And a couple of googles after I made the post above, I came across an answer:
globalThis.Intl = {
DateTimeFormat: function() {
this.resolvedOptions = function(){
return {
locale: "en-US"
}
}
}
}
Declared this at the start of the onRequest
function, and now it works.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论