HI Team, I am receiving date value from csv file ...
# suitescript
d
HI Team, I am receiving date value from csv file "30/11/2025" DDMMYYYY format When i try to set in NS using new Date("30/11/2025"), it doesn't throw any error , but the date is wrongly set as " 11/06/2027 ". I am using Map Reduce script while setting the value
b
use moment to convert the string into a Date
use moment timezone in the likely case you need to get the timezone correct
i heavily advise against using N/format, its for use with strings from within NetSuite
a
I would recommend the use of 'N/format' and only use moment for something more complex, like date calculations and stuff like that....
d
thank you @alien4u @battk
do i need to pass timezone in format API as well? I mean while using format module?
to set it correctly?
a
You don't need moment to handle time zones and server side date time...
@D17339
N/format
is complicated and
format.parse
is an overloaded method but the combination of
format.format
and
format.parse
should give you all you need.
d
@battk iam not able fix it
whether it could be because of csv file?
Copy code
{
         "ASN Date": "30/11/2021",
       
         Memo: "Test",
         Warehouse: "Jeddah",
         "Supplier Invoice Number": "12345678",
         "Supplier Invoice Date (ASN)": "30/11/2021",
         "Account (Main)": "NS11 External Inventory In Transit",
         "Actual Delivery Date": "30/11/2021",
         "Actual Shipping Date": "30/11/2021",
         "Trailer Number": "XXC 121",
         "Purchase Order": "PO70",
         Item: "102011000002",
         Units: "EA",
         "Production Date": "28/10/2021",
         "Inventory Detail Quantity": "1",
         "Inventory Detail Status": "Good",
         "Inventory Serial Lot Number": "XVX2",
         "Inventory Expiration Date": "30/11/2025"
      }
these are the data i am getting from csv file
b
your ability to use N/format is dependent on your company/s date/time format settings
normally its dependent on the user's settings, which is an untenable situation since different users can have different date/time formats
d
var myDateStr = dtSupplierInvoiceDate; log.debug('myDateStr',myDateStr) var dateArr = myDateStr.split('/'); var myNewDateString = dateArr[1] + "/" + dateArr[0] + "/" + dateArr[2]; var mynewDate = new Date(myNewDateString); log.debug('mynewDate',mynewDate) var formattedDate = moment(mynewDate).format('DD/MM/YYYY'); log.debug('formattedDate',formattedDate)
message has been deleted
I have cross checked both company and user preference both are DD/MM/YYYY format
b
a map/reduce only uses the company setting, so its possible to use N/format if the company's date format is DD/MM/YYYY
d
@battk var value= format.format({ value : mynewDate, type : format.Type.DATE, timezone: timezone }) log.debug('value',value) objASNRec.setValue({ fieldId: 'custbody_vc_asn_invoice_date', value: value});
tried that aswell still same issue
🤕
b
you dont need to do any Date stuff if both the csv and the company use the same date formats
just use setText
d
ok let me try with setText now
b
the important thing to know when working with date fields is that setValue uses a Date as the value
setText uses a string as the text
d
its a Date Field , will try using setText
b
i think you tried setting a date field using a string as the value, which will always fail
you didnt share enough code with either attempt to really tell
d
here the sample code
var objASNDetails = [ { "ASN Date": "30/11/2021", Memo: "Test", Warehouse: "Jeddah", "Supplier Invoice Number": "12345678DP1", "Supplier Invoice Date (ASN)": "30/11/2021", "Account (Main)": "NS11 External Inventory In Transit", "Actual Delivery Date": "30/11/2021", "Actual Shipping Date": "30/11/2021", "Trailer Number": "XXC 121", "Purchase Order": "PO70", Item: "102011000002", Units: "EA", "Production Date": "28/10/2021", "Inventory Detail Quantity": "4", "Inventory Detail Status": "Good", "Inventory Serial Lot Number": "XVX1", "Inventory Expiration Date": "30/11/2025" }]; var asnBodyValues = objASNDetails[0]; var strMemo = asnBodyValues["Memo"]; var strWarehouse = asnBodyValues["Warehouse"]; var strTrailerNum = asnBodyValues["Trailer Number"]; var strAccMain = asnBodyValues["Account (Main)"]; var dtActDelDate = asnBodyValues['Actual Delivery Date']; var dtActShipDate = asnBodyValues['Actual Shipping Date']; var strSupplierInvoiceNumber = asnBodyValues['Supplier Invoice Number']; var dtSupplierInvoiceDate = asnBodyValues['Supplier Invoice Date (ASN)']; if (lib.isNotNull(dtSupplierInvoiceDate)){ var timezone = config.load( { type: config.Type.COMPANY_INFORMATION }).getValue( { fieldId: 'timezone' }); log.debug('timezone',timezone) var myDateStr = dtSupplierInvoiceDate; log.debug('myDateStr',myDateStr) var dateArr = myDateStr.split('/'); var myNewDateString = dateArr[1] + "/" + dateArr[0] + "/" + dateArr[2]; var mynewDate = new Date(myNewDateString); log.debug('mynewDate',mynewDate) var formattedDate = moment(mynewDate).format('DD/MM/YYYY'); log.debug('formattedDate',formattedDate) var value= format.format({ value : mynewDate, type : format.Type.DATE, timezone: timezone }) log.debug('value',value) objASNRec.setText({ fieldId: 'custbody_vc_asn_invoice_date', value: value}); }
b
setText does not use the same parameters as setValue
💯 1
d
setText worked
does it work for setCurrentSublistText as well
yes i have changed the parameters as objASNRec.setText({ fieldId: 'custbody_vc_asn_invoice_date', text: value});             }
sample i didn't change
setText worked for all body values
@battk
if (lib.isNotNull(value["Inventory Expiration Date"])) objInvDetailSubRec.setCurrentSublistText({ sublistId: 'inventoryassignment', fieldId: 'expirationdate', text: value["Inventory Expiration Date"] });
but at inventoryDetail Sublist it failed
@battk MANY MANY THANKS
sublist also worked now
You are really awesome @battk I didn't think about making use of setText, since its a dat field