ディスカッション
NetSuiteの保存検索やレポートをマスターするための究極のガイドである分析センターを使用して、データの力を最大限に活用しましょう。複雑さを単純化し、組織の真の可能性を解き放ちます。今すぐ分析センターに参加して、新たな高みを目指しましょう!
New AI Community Guidelines. Please review and follow them to ensure AI use stays safe, accurate, and compliant.
Keep an eye out for upcoming NetSuite events, including meetups, workshops, and webinars. These sessions are a great way to connect with peers, learn from experts, and stay current on the latest NetSuite updates and best practices. Registration links are provided in each event.
日付フィールドから年の週を計算するスクリプト
適用
製品: NetSuite 2020.2
シナリオ
スクリプトは、日付フィールドから年の週を計算します。年の週機能は、保存検索ですぐ使用することができます。 SuiteScriptでは、以下のサンプルを使用してください。
年の週機能についてはSuiteAnswers ID:13470を参照してください。
解決策
SuiteScript 1.0を使用するサンプルスクリプト:
function WeekOfYear() {
var date = nlapiStringToDate(nlapiGetFieldValue('trandate'));
var target = new Date(date);
var dayNr = (target.getDay() + 6) % 7;
target.setDate(target.getDate() - dayNr + 3);
var firstThursday = target.valueOf();
target.setMonth(0, 1);
if (target.getDay() != 4) {
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
}
var Weeks = 1 + Math.ceil((firstThursday - target) / 604800000);
nlapiSetFieldValue('custbody101', Weeks);
}
SuiteScript 2.0を使用するサンプルスクリプト:
function WeekOfYear() {
var currentRecord = context.currentRecord;
var trandate = currentRecord.getValue({ fieldId: 'trandate' });
var target = new Date(trandate);
var dayNr = (target.getDay() + 6) % 7;
target.setDate(target.getDate() - dayNr + 3);
var firstThursday = target.valueOf();
target.setMonth(0, 1);
if (target.getDay() != 4) {
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
}
タグ付けされた:
0