Date format JSON expression in app studio

Trying to standardize a comment text under specific scenarios and I’m hoping to dateformat the value that gets copied into the text field. Is there a way to do this in the JSON editor on row-update?

1 Like

I would do it in a function. Pass the date value in, return a string formatted however you want, then just add {actionResult.FunctionReturnString} in your row-update.

1 Like

Haven’t tried but you might get somewhere with a JavaScript expression like:

#_ new Date(‘{OrderDtl.RequestDate}’).getMonth() _#

But if you’re trying to append this to the existing comment value, it may take a couple steps to first build the new value then row-update. (?)

Edit: The following does work in expression property (rather than json value) of row-update event to concatinate the month into the comment field if that’s what your trying to do.

'#_ new Date('{Part.OnHoldDate}').getMonth().toString() + '< MONTH NUM------' + '\n' + '{Part.CommentText}' _# '

Just don’t forget to put a “+1” after getMonth()

January is month 0.

1 Like

Very true thanks @dcamlin.

Also, assuming you want to replace the Month stamp rather than add another on every blur, this works:

'#_ (new Date("{Part.OnHoldDate}").getMonth() + 1) + " < MONTH NUM------" + "{Part.CommentText}".replace(/^\d+ < MONTH NUM------/, "") _#'

PS - Not sure how to do line feeds, the expression evaluator may be removing them. Not sure.

1 Like

This is pretty much what I was looking for, I too am still puzzled by how to insert a carriage return, but that’s not a deal breaker for me. It looks like the expression is stripping \ chars so I may need to find a way to somehow escape those.

This function was for inserting a datestamp in the comments field so that it’s consistent with a “MBAC” (must be at customer) note so they know to ship with enough time to reach by this date. Yes, I know the ship by should handle this, but it’s not always clear.

‘------------- MBAC #_ (new Date(“{OrderDtl.NeedByDate}”).getMonth() + 1) + “/” + (new Date(“{OrderDtl.NeedByDate}”).getDate()) + “/” +(new Date(“{OrderDtl.NeedByDate}”).getYear() +1900)+ " -------------\r\n" + “{OrderDtl.OrderComment}” _#’

1 Like

for mm/dd/yyy you could also try

new Date("{OrderDtl.NeedByDate}").toLocaleDateString("en-US")
2 Likes

Much cleaner for this use case, thanks.

1 Like