日期应为 DD/MM/YYYY 格式错误?

问题描述 投票:0回答:1

我正在尝试从发票中获取交易数据并将其设置在高级公司间日记账分录记录中。截止日期为 2024 年 2 月 12 日。当我执行 new Date(trandate) 时,它返回发票的空值,而对于某些发票,它给出正确的日期值。当新日期给出 null 时,它会给出错误日期应该采用 DD/MM/YYYY 格式。

另外,当我尝试使用 format.parse 或 format.format 时,它说 format.parse 或 format.format 不是函数。请帮忙!

var NS_MAX_SEARCH_RESULT = 1000; var JEIDArray=[]; 定义(['N /搜索','N /运行时','N /记录','N /任务','N /文件','N /文件','N /格式'],函数(搜索,运行时、记录、任务、文件、格式){

function execute(context) {
    try {
        log.debug("start execution");
        var scriptObj = runtime.getCurrentScript();
        log.debug("scriptObj",scriptObj);
        var searchID=scriptObj.getParameter({ name: 'custscript_aije_saved_search_id' });
        log.debug("searchID",searchID);
        
        var recordId =runtime.getCurrentScript().getParameter({ name: 'custscript_record_id' });
        log.debug("recordId param",recordId);
       
        
    var searchObj = search.load(searchID);
    searchObj.filters.push(search.createFilter({
        name: 'internalidnumber', 
        operator: search.Operator.EQUALTO,
        values: recordId
    }));
    var result = getMoreRecords(searchObj);
    log.debug("result.length",result.length);
    if(result && result.length>0)
    {
        createICJE(result,recordId);
    }
    } catch (error) {
        log.debug('Error in Create Journal Entry', error);
    }
}

function createICJE(results,invoiceId) {
    log.debug("inside craeteje");
    var counter=0;
    results.forEach(function (result) {
    // Access invoice data using saved search column internal IDs
    var invoiceNumber =  result.getValue({ name: "invoicenum", label: "Invoice Number" });
    var invoiceDate = result.getValue({ name: "trandate", label: "Date" });
    log.debug("invoice date",invoiceDate);
    var datenew=new Date(invoiceDate);
    log.debug("datenew",datenew);

            var journal = record.create({
            type: 'advintercompanyjournalentry',
            isDynamic: true,
            defaultValues: {
                customform: 136       
            }
        });
    journal.setValue('trandate', datenew);
    journal.setValue('postingPeriod', postingId);
    journal.setValue('subsidiary', subsidiary);
    journal.setValue('Currency', currency);
    journal.setValue('approved', true);
    journal.setValue('custbody_ay_cts_ayuk_project', AYUKProject);
    journal.setValue('memo', JEMemo);
    journal.setValue('custbody_ay_cts_master_allocation_tran', invoiceId);
    var journalId = journal.save();
    log.debug('Journal Entry Created', 'Journal ID: ' + journalId);
    JEIDArray.push({ item: itemId, amount: ayukAllocationAmount, JE: journalId });
 }
return {
    execute: execute
}

});

scheduled-tasks netsuite suitescript suitescript2.0 journal
1个回答
0
投票

构建日期对象

console.dir(Date('02/12/2024'));

© www.soinside.com 2019 - 2024. All rights reserved.