I want to have a rule, which changes the Document Date to the Date in the file name “YYMMDD_FileName”. I cannot figure out, how to use the function “Datum ändern” to use a variable from an action before for example like “Name scannen” or a “Chat Anfrage” - in the drop down I cannot choose anything but the standards. Can anyone help? Thanks!
I have a file with the date YYMMDD_ at the start of the filename according to the OP’s description (in the screenshot, an unrelated file is highlighted, though. I ran the smartrule on the one just above). And a smartrule
Here’s a script for a smart rule that does what you want. It’s written in JavaScript and obviously overcommented – but still created by Human Intelligence 1.0
Use it in an “Execute JavaScript” action in your smart rule, and make sure to select documents in the smart rule, too.
The code assumes that all dates are in the 21st century, i.e. “YY” at the beginning of the name is converted to “20YY” for the document date. If you have documents whose name reflects a date in the 20th century, you must adapt the code for that.
function performsmartrule(records) {
/* Loop over all records selected by the smart rule condition(s) */
records.forEach(r => {
/* Get the current record's name */
const name = r.name();
/* Check if the name begins with six digits followed by an underscore */
const matchDate = name.match(/^(\d{6})_/);
if (matchDate) {
/* For matching record:
convert the six digits to a date string in ISO format */
const rawDate = matchDate[1].replace(/(\d\d)(\d\d)(\d\d)/,"20$1-$2-$3");
/* Create a date object from the date string */
const date = new Date(rawDate);
/* Set the current record's date to the date from the name */
r.date = date;
}
})
}