Crow Canyon Software Forum

Forum Navigation
Please or Register to create posts and topics.

Dates formatting in workflow

Does anyone know what formula I could use just to get the YY-MM out of the a Due Date column?  I need to add that to a string for a format of something like YY-MM_LastName_FirstName.

Thanks

 

const duedate = currentItem.get_item("Due Date");

// all date parts, 2 digits:
const d = ("0" + duedate.getDate()).slice(-2);
const m = ("0" + (duedate.getMonth()+1)).slice(-2);    //just to make it fun, you have to add 1 since some of these fields are zero-based
const y = duedate.getFullYear().toString().slice(-2);
const h = ("0" + duedate.getHours()).slice(-2);
const n = ("0" + (duedate.getMinutes()+1)).slice(-2);   //just to make it fun, you have to add 1 since some of these fields are zero-based

// get other fields
const last = currentItem.get_item("LastName");
const first = currentItem.get_item("FirstName");

// put it together

const Answer = y + "-" + m + "_" + last + "_" + first

 

That works in the form itself when you open the form you can do a form event but what about in workflow?  I do not see a execute script function in Workflow.

Thanks

Sorry, we use it in a form, and also in a Custom Action to update the column if needed. It's probably not the most elegant solution but it has been working for us. Maybe someone else can chime in if there's a way to execute javascript in a workflow, but I kind of doubt it since workflows are executed on the server.

I've accomplished something similar by setting a variable using the regextract([value/placeholder],@expression) formula to strip the desired value(s) out, then using the strcat() function to combine your variable and the rest of your string.

All

Thank you I ended up using a version of the script to update the file name pre-save in a custom action and that resolved.

Thanks

Jennifer

Add a calculated column to the list. Use Excel functions to format the date, something like Concate(Text([DueDate],"MM_YY"),"_","[Lastname],"_","[Firstname]).

Then use the calculated field in your workflow. Of course hide the column in any views.