what is a valid date format for a client script?
# suitescript
a
what is a valid date format for a client script?
I have tested these values but all failed: 1612184761035 02/01/2021 "2021-02-01T120757.301Z" "01/02/2021 10525 pm"
t
Have you tried the date object ?
a
I need to get the data server side and pass it to the client script
@tuli what's your suggestion? how can I do that?
the third value is a date object, but didn't work.
p
Help us to help you. What are you actually trying to do? You're writing a client script. Where are you pulling the date value from? A form? A saved search result? An API? Somewhere else?
a
@PNJ It should be the end of each month
and it should be set server side
then it will be passed to the client script with the rest of an object
so to make it simple let's test now as a value
but I can't make it the client script
w
How will you pass it to the client script? How do you want to use it in the client script?
a
clientscriptmodulepath and functionName
and in client script
record.setValue()
w
Are you trying to create a date variable in a suitelet? or a beforeLoad-script? and then somehow pass that to a client script?
a
@Watz yes
beforeLoad
w
So how are you passing it to the client script?
b
the basics of this are you use setValue with a Date
use setText with a string
a
if it's possible I don't want to use setText
w
Copy code
var today = new Date()
var lastDayOfCurrentMonth = new Date(today.getFullYear(),today.getMonth()+1,0)
a
@Watz I'm passing the value by a function
and clientScriptModulePath
w
"by a function", what do you mean by that?
a
@Watz no that will not work
w
Show us your code.
a
like attaching a function to a button
w
And what does that function look like?
a
function will create the record and set the date value
a
yes
that's how I'm passing the date variable
w
as a string then...? use format.parse() to parse it to a date and then use setValue()
a
I didn't want to edit it client side
so there is no way
I need to parse it or use setText
w
What's so magical about the date in beforeLoad?
a
nothing but I didn't want to edit the object that coming from the server
t
I think passing ISO string to that function and parsing that back to date object in client script should work Something like
function XYZ(dateString){
var d = new Date(dateString);
...
...
record.setValue({fieldId:'trandate',value: d})
}
..but this will not work in view mode.
p
I'm going to regret asking this, but where does the button function get the date value from? Can't you just get that value the same way in the client script? Where does the date actually come from in the first place ?
a
@PNJ it's just a simple date object. yes, it can be generated the same way in the client script.
p
Sounds like a better plan then