My rule input is of type document of CDT to upload excel file into the database.
Discussion posts and replies are publicly visible
There is a dirty way of achieving it. People in the community do not recommend it but I have been using it for quite a long but in a way that if it ever stops working, I can just change the logic in the single expression rule to avoid errors.
tostring( a!fileUploadField(value: ri!doc).contents.value.filename )
For this to work, just create this in an expression rule and create the 'doc' ri should be of type document.
I eventually figured out a semi-workaround that doesn't require our old trick of "peeking at the back-end code of file upload field", for what it's worth... Note: this uses the Content Tools plug-in (which most projects hopefully already have installed).
a!localVariables( local!rawDetails: if( a!isNullOrEmpty(ri!doc), "", getcontentobjectdetailsbyid(ri!doc) ), index(extract( local!rawDetails, "[Name: ", ", UUID:" ), 1, null()) )
Note this returns the entire filename including extension of the uploaded document. In my use case I really wanted the name and extension separately for processing reasons, so I implemented a further rule that the name could be passed into and the name / extension are returned as dictionary properties. (Uses the RegEx plug-in)
/* GLBL_UTIL_processDocumentName() */ a!localVariables( local!hasNoExtension: search(".", ri!docName) = 0, local!namePart: if( local!hasNoExtension, ri!docName, regexsearch( pattern: ".*(?=\.)", searchString: ri!docName, regexFlags: "i" )[1].match ), local!extension: if( local!hasNoExtension, "", regexsearch( pattern: "[^\.]*$", searchString: ri!docName, regexFlags: "i" )[1].match ), a!map( name: local!namePart, extension: local!extension ) )
Combined, the original "get new uploaded doc name" rule in my system really ends up looking like this:
a!localVariables( local!rawDetails: if( a!isNullOrEmpty(ri!doc), "", getcontentobjectdetailsbyid(ri!doc) ), local!wholeName: index(extract( local!rawDetails, "[Name: ", ", UUID:" ), 1, null()), rule!GLBL_UTIL_processDocumentName( docName: local!wholeName ) )
...which gives this nice output:
Mike Schmitt
Interesting!!! Thanks for sharing.