How to pass notedate for User Notes in Netsuite using RESTlet? - netsuite

I could create and update User Notes in Netsuite for the customer.
The following data is working fine.
$columns_field= array("title","direction","notedate"); #_scheduled
$columns_values=array("Sample User Notes","2","4/30/2016");
$datastring = array('recordtype' => 'note', 'id' => '104','columnname' =>$columns_field,'columnvalues'=>$columns_values,'gu_action'=>'update');
But when i add time for notedate , it will not work. I want to pass date and time. i have tried these formats.
Like
4/30/2016 05:06 am
4/30/2016 05:06 AM
4/30/2016 14:32
I am having RESTlet file in the following link:
https://gist.githubusercontent.com/ganeshprabhus/68a9e5b81e53436bb1d684f857a6c31f/raw/67fe03895f1c31d65c1f283dd51584af45d27c59/NS_Script_2016.2004.
My reference link is :
https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2015_2/schema/record/note.html
Additional Requirement :
If possible, Please post the reference links.

For the Note record date and time are separate fields. Their script ids are "notedate" and "time" respectively.
So if you have a real Date:
note.setFieldValue("notedate", nlapiDateToString(datetime)); //'date' format i s the default
note.setFieldValue("time" , nlapiDateToString(datetime, 'timeofday'));

Try "2015-03-25T12:00:00" for your date string. That's a format that the Javascript Date object will understand, which is what you're ultimately working with in NetSuite (actually it's Rhino + Java, but close enough)
BTW, the T above stands for UTC time, so make sure to keep that in mind.

Related

Remove timezone completely from SQL Server

EDIT: Some users noted that this is a duplicate of ADO.NET question at
How can I get DateTime data from SQL Server ignoring time zone issues?
Please DO READ my tags, and my codes. This is nodejs question,
that has nothing to do with ADO library whatsoever. It doesn't
even run on Windows. The option noted at the link provided doesn't even exists at mssql-npm
I am creating a database for company attendance, which spans for 3 timezones.
The problem with SQL Server is that I read the working hour differently from each timezone. It registered like 1969-12-31T23:00:00.000Z, and registers as 06:00 for one timeline, and 08:00 for another. I need it to be exactly at 08:00 regardless of timezone. It means, 08:00 at western part of my country, and also 08:00 at eastern part of my country.
When I try to disable UseUTC, nodejs translated my timezone twice. For example, this is when I sent masuk field as 08:00
Sent to server:
Query sent to SQL Server:
UPDATE shift SET name = 'Shift 1', masuk = '2019-10-28T01:00:00.000Z', keluar = '2019-10-28T10:00:00.000Z', tolerance = 15 WHERE id = 1
Received the result back
And shown to the user as:
My country sits at GMT+7 to GMT+9. I don't mind if I have to flatten the timezone. But how to do that? Is there a way to read the time completely ignoring the time zone? It makes my work unnecesarily complicated.
I am using:
SQL Server 2012
Material UI
date-fns
Nodejs 12
mssql module
and this is my code to get the time from user input
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<KeyboardTimePicker
key={component.field.toString()}
variant="inline"
value={value}
label={component.title}
onChange={this.eventHandler(component.field).bind(this)}
format="HH:mm"
/>
</MuiPickersUtilsProvider>
Thank you for help.
THe database uses time(7) to store the time

Mongoose datetime and timezone, how to get datetime based on server timezone

The first answer of this question suggests that mongoose would adapt the date according to server timezone when retrieving data.
However, I don't have this comportement.
I set the (node) server timezone with :
process.env.TZ='Europe/Paris'
For exemple if I create a simple model like :
const mongoose = require("mongoose");
const testSchema = new mongoose.Schema({
myDate: { type: Date, required: true },
}, { timestamps: true });
exports.Comment = mongoose.default.model('TestSchema', testSchema);
But if I create a date with 2020-01-01 20:20:20, when doing TestSchema.find() the date will be: 2020-01-01T19:20:20.000Z so there are two things that I don't understand :
Europe/Paris is actually UTC +2, so I would expect the date to be either 2020-01-01T18:20:20.000Z in UTC or 2020-01-01T20:20:20.000Z with the server timezone
How to have mongoose automatically set the date to the correct timezone?
I know that myDate is a Date object, so I can convert it manually but I'd rather not have to do it myself for simple reasons like forgetting to convert one of the dates in the application or not having to do it every time a Date field is added
An easy solution that I can think of would be to register a global plugin for mongoose which would use schema.set('toJSON', ... and schema.set('toObject', ...) with the transform method so I can loop through schema fields and if the field is a Date, update it to my timezone.
But I see two problems with this approch :
It doesn't sound very good performance-wise if I am querying a lot of documents each with a lot of fields
As you can see here I am currently not able to register global plugins...
What would be the best method to get the date in the server timezone format? I would rather still store them in UTC but set the hour according to the server timezone.
EDIT :
I just saw that while console.log(myDate) outputs 2018-01-01T19:20:20.000Z console.log(myDate.toString() outputs Mon Jan 01 2018 20:20:20 GMT+0100 (Central European Standard Time) so it seems likes this could be used, even tho I'd rather still have a Date object and converting it to string just before sending it to the client (would need some formatting tho since this format is not very user friendly). But then again, how would I do this globally and not for every date
A few things:
Europe/Paris at 2020-01-01T20:20:20 is UTC+1. It doesn't switch to UTC+2 until Summer Time kicks in on March 29th. Reference here. Thus the conversion to 2020-01-01T19:20:20Z is correct.
The output of console.log when passed a Date object is implementation specific. Some implementations will emit the output of .toString() (which is in local time in RFC 2822 format), and some will emit the output of .toISOString() (which is in UTC in ISO 8601 extended format). That is why you see the difference.
In general, it is not good to send a local time without also sending a time zone offset. ISO 8601 format is ideal, but you should send either 2020-01-01T19:20:20Z, or 2020-01-01T20:20:20+01:00. Don't just send the date and time without an offset to the client. Otherwise, if your client could be in a different time zone then they would interpret the value incorrectly.
Keep in mind that Date objects are not time zone aware. They contain only a Unix timestamp internally, and they convert only to the system's local time zone for the functions that work in local time. They cannot work in any other time zone.
Relying on the system local time zone is bad for portability. One doesn't always have the ability to change it, and it doesn't do well when you have to work in multiple time zones. It would be better to not rely on setting a local time zone from Node's TZ variable. Instead, consider writing your code to be independent of any local time zone setting.
A time zone aware date library can help with most of your concerns. I can recommend Luxon, js-Joda, Moment + Moment-Timezone, or date-fns + date-fns-timezone.
"how would I do this globally" is something I'm not following in your question. Try the approach I described, and if you still have issues then open a new question. Try to be specific and ask a single question. You're likely to get better results that way. Please read How do I ask a good question? and How to create a Minimal, Complete, and Verifiable example. Thanks.
To solve the issue:
npm i mongoose-timezone
In your schema file:
import timeZone from "mongoose-timezone";
const testSchema = new mongoose.Schema({
myDate: { type: Date, required: true },
}, { timestamps: true });
// mongoose will save the dates based on user's timezone
testSchema.plugin(timeZone)
mongoose-timezone basically adds the current timezone offset to the
date before store and removes the offset when retrieving data. This
way dates are kept proportional in the database and in the app.

how to display local date/time in browser?

I am coding an nodejs express application. The dates are stored in database using the UTC date/time. I'd like to display the date/time in the user's local time zone. how could I implement this?
Thank you in advance.
Richard Xu
In your template you could do
<span data-date-utc="Wed, 25 Apr 2018 18:16:13 UTC"></span>
Then use js to render it in the users local time (I'm using jQuery here to extract the date string, then render it back to the page)
$('span').text(new Date($('span').attr('data-date-utc')).toLocaleString());
You can use any of the Date Object methods in place of toLocaleString to render your output however you want
Use the moment npm package and for more information refer to the momentjs documentation.
var utcDate = moment.utc("2018-04-26 10:00:00");
var localDate = moment(utcDate).local();
Now you can use the below function to format the date accordingly.
localDate.format("YYYY-MM-DD HH:mm:ss");

Timezone bug when retrieving "time" field?

The manual specifies that uniqueness is based on foreign_id and time fields.
I have an activity where a user joins a specific event. The event has its own start date which I want to display in the timelines, therefore I am submitting it as extra data (as well as name and location etc, but I omitted those here to prevent clutter).
I submitted the activity with the following activity array to a user feed. Notice I am in Amsterdam, which is (at the moment) in a timezone of GMT+0200:
Array
(
[actor] => User:3
[verb] => join
[object] => Event:2
[event_start] => 2016-09-26T19:00:00+0200
[to] => Array
(
[0] => notification:2
)
[foreign_id] => join:2
[time] => 2016-09-16T13:29:13+0200
)
When I retrieve that users' user feed, this comes back as:
{
"duration":"17ms",
"next":"",
"results":[
{
"actor":"User:3",
"event_start":"2016-09-26T19:00:00+0200",
"foreign_id":"join:2",
"id":"cb0f4a80-7c00-11e6-8080-80010479bedb",
"object":"Event:2",
"origin":null,
"target":null,
"time":"2016-09-16T11:29:13.000000",
"to":[
"notification:2"
],
"verb":"join"
}
]
}
Notice the difference in the date fields. Both were submitted as ISO8601 fields, but only the event_start field is returned as such. The time field is returned in a different format but without any timezone indicator. It's apparently converted to UTC time but it's lacking the trailing Z that should indicate that. Therefor I cannot reliable use it as a time indicator.
I could work around this by adding another time field to the activity array (which works fine and returns a correct ISO8601 date), but that feels quite redundant.
Is this a bug, am I doing something wrong or should we simply not rely on the time field for an indication of when the activity took place?
API v1.0 stores the time field in UTC timezone but sadly it does not properly return the trailing Z. This will be fixed in later API versions, but not on this one.
You can safely expect the time field to be always returned as UTC when you query the APIs.

How can I clear an external ID on a record in NetSuite?

I need to clear/reset the external ID on a record in NetSuite, but nothing I do is working.
Some of the InventoryItem records are incorrectly mapped to records in another system. I have an application that can sync up the two systems, but I need to clear NetSuite's external IDs first.
Responses don't really need to be SOAP-specific. If you know how to do it with some specific NetSuite/SuiteTalk client, that might point me in the right direction.
What I've Tried
First up, I tried using the nullFieldList... but maybe it doesn't work because externalId is an attribute, not an element?
<messages:update>
<messages:record internalId="7777" xsi:type="accounting:InventoryItem">
<core:nullFieldList xsi:type="core:NullField">
<core:name>externalId</core:name>
</core:nullFieldList>
</messages:record>
</messages:update>
The external ID is just a string, so I tried just setting it to blank. Didn't work either.
<messages:update>
<messages:record internalId="7777" xsi:type="accounting:InventoryItem">
<accounting:externalId></accounting:externalId>
</messages:record>
</messages:update>
I even tried setting the external ID to 0, but I get back a "not unique identifier" error
<messages:update>
<messages:record internalId="7777" xsi:type="accounting:InventoryItem">
<accounting:externalId>0</accounting:externalId>
</messages:record>
</messages:update>
Other Info
I'm using NetSuite's SOAP API v.2013_1
When I say "it doesn't work", I mean: after I do the update, I get a success response similar to the following:
<readResponse>
<platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2013_1.platform.webservices.netsuite.com"/>
<record internalId="7777" externalId="42" xsi:type="listAcct:InventoryItem" xmlns:listAcct="urn:accounting_2013_1.lists.webservices.netsuite.com">
<!-- snip -->
</record>
</readResponse>
If you are using scripts in netsuite you can run a scheduled script to clear records in NS by loading each record and setting the externalid to '' using the following simple code:
var rec= nlapiLoadRecord(type,id);
rec.setFieldValue('externalid','');
nlapiSubmitRecord(rec);
This seemed to work for me in my enviornment which was on 2015.2.
Unfortunately my understanding is that once you set an externalid you cannot clear it, you can set it to another value, but not back to null. I have experienced this both using SuiteScript as well as a Boomi process that uses the 2014.1 endpoint. This may have changed in the recent releases, as I have not tried it recently with SuiteScript nor with a newer endpoint.
You can eliminate the externalId on a record once it's been set. Here's an example using the NetSuite gem:
ns_customer = NetSuite::Records::Customer.get external_id: 'ext_id'
ns_customer.external_id = ''
ns_customer.update
Here's the corresponding XML for update:
<env:Body>
<platformMsgs:update>
<platformMsgs:record xsi:type="listRel:Customer" platformMsgs:internalId="199113" platformMsgs:externalId=""/>
</platformMsgs:update>
</env:Body>
I have had to attempt this before as well. I know the pains you describe. I ended up putting a "-" in front of my external ID to unlink it between my systems. You can do this in SOAP or even as a simple one time csv upload. As it was one time, I did csv.

Resources