I’m using a rules filter to grab files from one folder that have Congress bioguide IDs (like A000378) at the beginning of them and a human readable name after them, this works great.
After processing, I’d like to write the files out to just the bioguide ID as the filename so they’re predictable when generating urls and not having to worry about names / nicknames.
Is there a way to set custom filename tokens based on the previous rules filter? Or appling the matches from regex groups when writing names would also work.
You can do it with a JavaScript node, with the contents as such:
function processAsset(document, jsnode, asset) {
var currentName = asset.outputFileName() + ""; // make sure it's a js string.
// Apply a regex to the name.
currentName = currentName.replace(/t/g, "X");
asset.setOutputFileName(currentName);
// Just another example here, of setting values to be used in the token fields.
asset.setUserValue_forKey("FOO", "myKey");
return true;
}
So that’ll rename the file name, replacing all ‘t’ characters with a capital X.
Then we also add a little “userValue” of “FOO” for the key of “myKey”. That value is then referenced later on in the write node like so:
Just posting in case this helps someone else… I had trouble using asset.setOutputFileName() and asset.setUserValue_forKey() when followed by the Layer & Page Splitter action! Had to move Javascript after Page Splitter in the workflow.
The splitter node will probably make up its own values for those new assets, so that kind of makes sense. I’ll have to check the code to make sure though - but adding it later certainly works.