Vadim Tabakman

Jump to bottom

Nintex Workflow - Get File Extension UDA

Although figuring out the file type can be as simple as checking the content type, sometimes that doesn't give us the data we need.  In this case, any document can be uploaded to a document library in SharePoint and I have a need to figure out the file type.

The easiest way I can think of, is to check the file extension.  That way, if I needed to, in my Nintex Workflow, I could use a Switch action to handle the different file types with different business logic.

I built a Nintex Workflow User Defined Action, because I can see myself using this logic in other workflows, and I don't want to have rebuild it.

User Defined Action - Design

Here is the design.  It's quite simple, only 5 actions.

The UDA will have 2 parameters.

1. File URL (input)

2. Extension (output)

Now granted, you could extend this, so that if you passed multiple URLs, it would give you back multiple extensions.  It wouldn't be that hard to do... but I didn't have that need with this UDA.

I want to highlight the important actions in this UDA.

The first being the Regular Expression.  If you don't know already, I love this action. It's so powerful.

Notice the expression \w+$.

The \w represents a word, but essentially it's character.  The plus, tells it to find 1 or more characters together.  The $ sign says, look for the end of the text.  This won't match a dot/period, which means, we should get back the file extension.

BUT!!! Since we are doing an Extract that only allows us to store the data in a Collection variable.  Which means, we need to add a little logic to the UDA, to check that we have data in the collection and if we do, pull out the first result.

The final action is a Build String action.

The reason for the Build String action, is to call the fn-ToLower inline function. This will take the file extension and make it lower case.  I wanted to do this, because from the workflow that would eventually call this UDA, I don't want to have to check for multiple file extensions, that are essentially the same. eg. csv CSV CsV csV etc.  This UDA will send back "csv" and "docx" etc.  It will make it easier for me to use this in a Switch action later.

Conclusion

I hope this helps you guys.  If you have any questions, comments or suggestions, please post them in the comments below.

Downloads

Nintex Workflow 2013

Download the User Defined Action - Download it and import into the New User Defined Action page

Copyright Vadim Tabakman
Rate this Content 0 Votes

Comments

Thursday, January 21, 2016 2:01:34 PM
Henning Eiben
Gravatar

re: Nintex Workflow - Get File Extension UDA

Hi, 

You could also just use "\.(\w+)$"  as the regex, which should just return one match, which is the actual extension. 

Thursday, January 21, 2016 2:15:04 PM

re: Nintex Workflow - Get File Extension UDA

Nice one :) thanks for sharing,

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register
  • RSS





 

Statistics

  • Entries (239)
  • Comments (1722)

Categories