A web request gives me '2022-03-01'.
I know that is and always will mean UTC 2022-03-01 at midnight exactly.
I need to copy that value onto another CRM date field on the Form
I tried:
var passDateToLib = Date('2022-03-01')
formContext.getAttribute("new_otherdatefield").setValue(passDateToLib)
That new_otherdatefield field is also configured to be a UTC Date only field.
But what ends up shown in the field, is 1 date BEFORE '2022-03-01'. So I suspect it's ignoring the timezone aspect of the Date...
toISOString() gives the time in ISO format. To get the date only as you mentioned we can use substring method to remove the time. This will basically give the date based on GMT and not for your Local TimeZone.
new Date().toISOString().substring(0,10);