<@UPHDYQS83> Can you post your code?
# suitescript
k
@Ali Can you post your code?
a
actually I'm using date object.
Copy code
new Date(parseInt(Y), parseInt(M) - 1, parseInt(D))
and it was till last week, we've tested it a hundred times.
k
is it in ss2.0?
a
yes
we haven't changed the version
k
what is the full code where you are setting the value.
a
in the phone call
Copy code
Call.setValue('startdate', startDate)
that's an after submit user event
k
and the startDate variable is what?
a
is that because of some changes in NS server?
k
Would be alot easier if i saw the full code snippet for this?
and yes could be.
a
is the result of this
Copy code
new Date(parseInt(Y), parseInt(M) - 1, parseInt(D))
k
Difficult to look at indivudal lines and try to diagnose the problem.
a
which when I test it in my system is
Copy code
Thu Jan 09 2020 00:00:00 GMT+0000 (Greenwich Mean Time)
k
yeah that is the date object value
a
I will receive this string from the user side
Copy code
08/01/2020
andconvert it to a date object
and set it to the phone call date field
k
If i got that date from user then i would use the format module to convert to date object. then use that to set the value.
a
how can I use the format module?
and what if I don't want to use the format module? is it possible?
k
The format module is the go to for me.
But if that field start date accepts a date boject then you shouldnt have an issue.
If it was working and now isnt which i find a bit odd then mahybe raise a casewith NS
b
generally code that doesn't use the format module tends to fail when people from different timezones use different time formats
k
That would be why it is now my goto.
a
how can I use format for that?
ill say that something unusual is going on if you are starting from the string 08/01/2020
primarily where did that string come from
a
Copy code
from a date field - client side
shall I use format.parse or format.Timezone?
b
what does the code to get the field look like
a
Copy code
getValue('custpage_phone_new_schedule_date') as string
b
if custpage_phone_new_schedule_date is setup as a Date field, you should be able to directly pass its value to setValue
a
yws it's date field
b
dont convert it to a string
a
I've test that
the result was the same error
I've removed as string and the error was:
Copy code
"INVALID_FLD_VALUE","message":"Invalid date value (must be DD/MM/YYYY)",
the issue as you said is different time zone
client system and netsuite server and I think we can't fix that even if we were able to pass the value directly
netsuite server will convert it
or no I'm wrong?
b
one of the purposes of format.parse is to take a string formatted in current users timezone and date/time preferences and convert it to a Date
the complimentary format.format takes a Date and convert its to a date/time string in the current user's preferences
however, if you are starting from a netsuite formatted date/time string, you dont need to do any conversion
a
so It should be good to go
but it's not
b
do
Copy code
Call.setText({ fieldId: "startdate", text: "08/01/2020" });
use setText with a date time string, use setValue with a Date
a
yes that works
thanks
so what was the issue with the date field
it's a date field so I don't need to convert it
b
you didnt convert it using format.parse
so it will fail on different date time formats
a
but you said we don't need to using format if it's a netsuite date field
b
you were trying to use setValue
setValue requires a Date
"08/01/2020" isnt a Date, its a string
you wrote a function to convert the string to a Date
probably by splitting by '/'
and taking the first, second, and, third splits and placing them in the Date constructor
that approach will fail for "2020/01/08", which is the same Datetime string in a different format
k
When @Ali is getting the value from the custom field though wouldnt it be a date object anyway? If it is then he sohould be able to set it directly to th startdate field.
@Ali I would log the typeof FIELDID and see what the typeof datat is.
a
that's for sure date I can see calendar next to that
k
log.debug({title: 'typeof custpage_phone_new_schedule_date', details: typeof YOUR VARIABLE FOR THIS FIELD});
a
No I have problem with tsetText as well when I select tomorrow I can't set that but the day after tomorrow and after that is ok
k
log what i said and see what you get.
b
custpage_phone_new_schedule_date is a field from N/ui/serverWidget, it doesnt have the fancy conversion to a Date using getValue
k
ah yeah it is a script created field.
a
yes
k
My bad!! didnt see that.
a
so what's the solution at the end
b
not sure what your new problem is
a
I have same problem even with this code:
Copy code
parse({value: reScheduleDate, type: format.Type.DATE})
Copy code
format({value: reScheduleDate, type: format.Type.DATE})
it's the same problem invalid date value
all future dates are ok except tomorrow
k
well that dont make any sense. lol
a
with setValue, setText, and using format.format and format.parse
k
I’ve gotta bounce. Sorry i have been unable to help.
a
all same error for tomorrow
b
whats the value of reScheduleDate
a
Copy code
09/01/2020
10/01/2020 is ok
just I can't set tomorrow
and I think it's because of the time zone, isn't it?
b
sounds weird
netsuite 1
what is the Date format of the current user?
a
interestin
I can even use today
but not tomorrow
b
the thing is that after tomorrow is double digit days
a
DD/MM/YYYY
b
and that only matters if your date format uses D instead of DD
a
what about today? it should be the same as tomorrow.
long date format is
Copy code
D Month YYYY
oh
tomorrow without start time and end time is ok
because i'm setting start time and end time for phone call too
but with that there is a problem
so I can set date and time for all days
except tomorrow
tomorrow with date only is ok
but with time there is a problem
this is the code for set start and end time
Copy code
startTime = new Date(parseInt(Y), parseInt(M) - 1, parseInt(D), startHour, startMinute)
                            endTime = new Date(startTime.getTime() + (30 * 60000))
b
same problem
a
startHour and startMinutes are numbers
b
where does Y and M come from
a
as you said split('/')
and then new Date
b
where is the value you are splitting coming from
a
date field
09/01/2020
b
how do you get a start time from that?
a
sorry, start time
comes from another text field
I parse that to a number
b
text? or time of day?
a
text
I'll parse that to a number and then
Copy code
let startHour = Math.floor(startTimeFld / 60)
let startMinute = startTimeFld % 60
b
whats a value that someone would enter into that field?
a
it's for example 480 for 8 AM
b
as in some person enters 480 into your custom text field
or enters 8 am into your custom text field
a
no user will select 8 am
it's a list
text is 8 am
value 480
b
thats not a text field
that a select field
a
sorry my bad
b
that solution requires you to manually convert 8am into the current user's time of day format
that can be something like 8:00 pm
or 20:00
i personally recommend you change your field to time of day
a
how can I do that? and why I don't have problem for other days and time
and it's just for tomorrow date with time
b
at this point im guessing there is something wrong with how your code works together as a whole
k
Seems a bit odd when you can use time of day
It looks like it needs a bit of optimising. Lol
a
Copy code
const campaign = (getValue('custevent_campaign_phone_join') as string).replace('C', '')
            if (campaign) {
                const reScheduleDate = getValue('custpage_phone_new_schedule_date') as string

                if (status.length < 2 && reScheduleDate) {
                    const [D, M, Y] = reScheduleDate.split('/')
                    if (M) {
                        const startDate = new Date(parseInt(Y), parseInt(M) - 1, parseInt(D))
                        const startTimeFld = parseInt(getValue('custpage_phone_new_schedule_time') as string)
                        let startTime, endTime

                        if (startTimeFld) {
                            let startHour = Math.floor(startTimeFld / 60)
                            let startMinute = startTimeFld % 60
                            startTime = new Date(parseInt(Y), parseInt(M) - 1, parseInt(D), startHour, startMinute)
                            endTime = new Date(startTime.getTime() + (30 * 60000))
                        }

                        const title = getValue('title')
                        const phone = getValue('phone')
                        const assigned = getValue('assigned')
                        const company = getValue('company')
                        const contact = getValue('contact')

                        let scheduledCall = createRecord({ type: Type.PHONE_CALL })
                        scheduledCall.setValue('startdate', startDate)
                        scheduledCall.setValue('title', title)
                        scheduledCall.setValue('phone', phone)
                        scheduledCall.setValue('assigned', assigned)
                        scheduledCall.setValue('company', company)
                        scheduledCall.setValue('contact', contact)
                        scheduledCall.setValue('custevent_campaign_phone_join', campaign)
                        if (startTime) {
                            scheduledCall.setValue('timedevent', true)
                            scheduledCall.setValue('starttime', startTime)
                            scheduledCall.setValue('endtime', endTime)
                        }
                        scheduledCall.save()
                    }
                }
b
easy fixes is the use time of day and use its text directly
hard fix is changing your start timem code to use setText instead of setValue
primarily because Dates are very hard to work with if you need to account for different timezones
a
so if I use setText for start and end that should fix?
b
setText requires the string to be in the current user's time format
8am is not guaranteed to be in the current user's format
you can either write code to change it to the curren user's time format
or use a time of day field instead
time of day is guaranteed to be in the current user's format
a
what's time of the day, I think I can't use that
because I need times from 8 am to 8 pm every half an hour
8 am 8:30 am and ...
b
Copy code
form.addField({
    id : 'custpage_phone_new_schedule_time',
    type : serverWidget.FieldType.TIMEOFDAY,
    label : 'start time'
});
a
remember that's a select field
is that the same?
b
nope
if you go for a select field, you need to do the conversion yourself
a
I think that's the solution
how can I do that
b
get the text of the field (8 am), read the current users time format (h:mm a), then convert it to the correct text value (8:00 am) then use setText with your starttime field
use N/runtime to get the current user's time preference (https://system.na0.netsuite.com/app/help/helpcenter.nl?fid=section_4296668859.html)
keep in mind there are 4 time formats, so you should handle all 4 cases
a
that's a bit difficult for me to understand any other easier solution?
text 8:00 am
then read the format
how convert it to text value?
b
depends on the format
you have to handle the conversion yourself
a
let's say all the format's are
hh:mm AM/PM
b
no conversion needed
8:00 am matches that format
a
just i need to find out a way to add 30 minutes for the end time right
b
that would consist of replacing the characters 00 with 30
a
and 30 with 00 and add 1
what's time of the day
is that a fild with time selection?
b
try it out yourself
add a field your field of type time of day
a
no it's like a test field
user don't know what to write inside that
another thing is error complaining about
dd/mm//yyy
not start and end time
I think it's something wrong with
09/01/2020
not 09/01/2020 8:00 am
b
you can try hardcoding values into it until you find one that works
then compare it to the value you are getting from your field
a
Thanks