Hi. I'm brand new to functions but I'm trying to create a script to convert a date field in Meetings to a written format. For example, instead of 02/05/2025 8:00AM, I'd like to convert it to Wednesday, February 5, 8:00 AM. My Date field is the API Name Start_DateTime, and the custom field I created is Meeting_Date_Written
I would suggest you can try the below code and share the complete response screenshot. Please make sure the API name of the Meeting_Date_Written is correct.
// Debug: Log the incoming parameters
info "Record ID: " + id;
info "Start DateTime: " + Start_DateTime;
// 1. Retrieve the meeting's start date/time from the parameter
a = Start_DateTime;
// 2. Format the date/time into a human-readable string.
// This will output something like "February 06 2025, 08:00:00 AM".
b = a.toString("MMMM dd yyyy, HH:mm:ss a");
info "Formatted Date: " + b;
// 3. Create a map to convert a numeric day-of-week into a day name.
mp = Map();
mp.put(1,"Sunday");
mp.put(2,"Monday");
mp.put(3,"Tuesday");
mp.put(4,"Wednesday");
mp.put(5,"Thursday");
mp.put(6,"Friday");
mp.put(7,"Saturday");
info mp;
// 4. Get the day of the week as a number (1-7) from the date.
c = getDayOfWeek(a);
d = mp.get(c);
info "Day of Week: " + d;
// 5. Concatenate the day name and the formatted date string.
e = d + ", " + b;
info "Final String: " + e;
// 6. Update the record's custom field "Meeting_Date_Written" with the final string.