Maira S
Maira S

Reputation: 47

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!

var NS_MAX_SEARCH_RESULT = 1000;
var JEIDArray=[];
define(['N/search', 'N/runtime', 'N/record', 'N/task', 'N/file', 'N/file', 'N/format'], function (search, runtime, record, task, file, format) {

    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
    }
});

Upvotes: 0

Views: 67

Answers (2)

Krypton
Krypton

Reputation: 5276

The issue is that you're importing N/file twice in your define, which means that format ends up bound to the N/file module, rather than the N/format module.

Change this:

define(['N/search', 'N/runtime', 'N/record', 'N/task', 'N/file', 'N/file', 'N/format'], function (search, runtime, record, task, file, format) {

to

define(['N/search', 'N/runtime', 'N/record', 'N/task', 'N/file', 'N/format'], function (search, runtime, record, task, file, format) {

Upvotes: 1

Ronnie Smith
Ronnie Smith

Reputation: 18585

build date obj. put in try / catch / finally block

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

Upvotes: 0

Related Questions