Date should be in DD/MM/YYYY format error?

I am trying to get trandate from invoice and set it on advanced intercompany journal entry record. trandate is 02/12/2024. when I do new Date(trandate), it returns null value for invoice, and for some invoice it gives correct date value. When new Date gives null, it gives error date should be in DD/MM/YYYY format.

Also when I tried to use format.parse or format.format, it says, format.parse or format.format is not a function. Please help!

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
}

});

Beginner Asked on December 2, 2024 in SuiteCloud.
Add Comment
2 Answer(s)

getValue returns a date object and setValue for date type fields must also be passed a date object

Rookie Answered on December 10, 2024.
Add Comment

I’d try getText() and setText() so that you can use the raw date string.

Advanced Answered on December 4, 2024.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   SuiteMigration   Become a Sponsor