Skip to main content

In my workflow I am trying to use the Update Item for all uploaded documents to modify the Name and Title. In case of the Name I would like to do the following:

  • remove spaces
  • capitalize first letter of every word (CamelCase)
  • remove dots, hyphens or underscores (helpful but not required if too complicated)

Anyone had an idea what kind of regular expression can do the above? Thanks!

Hello,

this Blog post should help you.

Here an use full website were you can see if your regex removes all other characters

hobe it helps,

br oli


I saw it but it is only a partial solution. Looking for something that can accomplish all my requirements...


Ok, basically with the blog you have the main part , capitalizing every single word(just use it in on regular expression action)

The second / third part is a matter of seconds to find via google (Use it in an second action, so it is much easier to fulfill your requirement's) wink.png

Br Oli


I assume I need to use the Replace operation. What should be in the Replacement text field? Thanks!

2016-04-11_14-11-19.png


Now I got you (sry wink.png ), it is not that simple to capitalize the first letter of each word.

Just with workflow configuration (none code solution), I only see the way described below:

1. Replace the characters which are unwanted with an defined on e.g. Underline _

2. Split the title/name of the document by the underline

3. Remove all empty values form the collection

4. iterate through the rest of the words within the collection, get the first character

5. Replace the character with it's uppercase representation

6. Replace the first character of the current word in the collection with the uppercase character

7. after that, concat your new document name/title

But for me it sounds easier to write a CSOM (JavaScript) to do this conversation in JavaScript.

Or writing an CustomAction (Needs Visualstudio an an full trust solution, only possible for Nintex OnPremise, which can't be brought to SharePoint online.)

Hope I could help, br oli


Hi,

If you use the built-in inline functions you'll find this a lot easier.

1. To capitalise each word use the fn-ToTitleCase inline function.

182550_pastedImage_0.png

2. To replace spaces or characters use the fn-Replace inline function

182551_pastedImage_1.png

182567_pastedImage_2.png

Hope that helps.

Jan


Replacement text is the text you replace matched with.


Be careful with the quotes in fn-Replace, looks like you don't need any: fn-Replace({WorkflowVariable:variable name},-,)


I have tried the code and it works, pretty sure you do need quotes.


I am testing this solution and I think I have a "quotes problem"... On one of my test files I have a comma and that seems to cause the action to fail. Can you please enlighten me how to use the Replace function to remove the comma? I put quotes around the string but that doesn't help.

This is my string: NS-SS-2013-7250 Checking Outputs, Inputs and Faults

Here is my action: fn-Replace({WorkflowVariable:varNameNoExt},",","")
2016-04-12_9-23-11.png

And this is the result (with commas and without):

2016-04-12_9-29-30.png


Hi Jan,

I agree with Alexey Krasheninnikov as well. For me most formulae work without the quotes. This is from NW help file:

fn-Replace

Replaces a section of text in a larger string.

Example:

fn-Replace({WorkflowVariable:Text},abc,{ItemProperty:Title})

Arguments

 Text The text to modify.

 Old value The text to search for and replace.

 New value The text to replace Old value with.

Igor Karon,

Comma ',' is tricky thing to remove with build string because as soon as the function encounters ',' it terminates the string and treats the portion after ',' as next part of the function.

Your build string become: fn-Replace(NS-SS-2013-7250 Checking Outputs, Inputs and Faults,",","")

which you can see is not correct. Till outputs, it will treat it as a string to replace. Have you tried this with calculated column in SP list?

REPLACE(Pcolumn],SEARCH(",",Hcolumn]),1,";")  - will replace the first occurance of , with ;

also

PROPER(Pcolumn]) with change text to title case.

You can also use regular expression action in workflow to replace ','

regex1.JPG

If this doesnt work, you may have to find javascript option.


Here is a way to do this with Build String:

fn-Replace(({TextStart}NS-SS-2013-7250 Checking Outputs, Inputs and Faults{TextEnd},{TextStart},{TextEnd},)

The result will be: NS-SS-2013-7250 Checking Outputs Inputs and Faults.

happy.png

{TextStart} and {TextEnd} will treat the whole string without breaking it in between and you can use this to compare the special characters as well.


Igor Karon, if you haven't already solved this, I have a solution that meets your requirements using a combination of regex and inline functions.  Below are the instructions for how to set it up.  

Variables

I setup the following 3 variables

VariableDescription
st_FileNameText variable that will be used throughout the workflow to store the formatted filename.
st_FileExtensionText variable for storing the file extension. Used at the end of workflow to reconstruct the full file name. 
c_FileExtensionCollection variable for storing getting the file extension.  The Extract Regex operation that is used only saves to a collection variable.

Variables Setup

1. Set File Name Variable

I set the file name variable (st_FileName) to the documents Item Display Name.  This is the file name without the extension. 

Set File Name Variable

2. Get File Extension

Next I extract the file extension and store it in a text variable.  This is a 2-step process.  

The first step is to use a Regex action to extract the extension using the regex .<0-9a-z]+$

The Extract operation will only save to a collection variable, so that is where we have to put it. 

Regex to get File Extension

The 2nd step is to remove the extension from the collection variable and put it in a text variable.  Use a Collection Operation and the Pop operation and store it in the Extension variable (st_FileExtension)

Take file extension from collection variable and put in text variable

 

3. Remove Commas (regex)

The next step is to remove any commas.  As you discovered, a comma in the file name will break an inline function.  So this must be done first before we use any inline functions. Use another Regex action. Enter a single comma in the pattern section.  Select the Replace text operation, and leave the Replacement text box empty. The input text will be our filename variable (st_FileName), and we will store the results in the same variable.  

Regex to remove comma

4. Capitalize First Letters (inline function)

Next we will capitalize the first letters of each word.  For this we will use a Build string action with the inline function fn-ToTitleCase.  It's important to do this before we remove all the spaces, hyphens, etc. from the file name.  Because after we remove all those characters, the file name will just be a single long name, and if we used this function then, only the very first letter of the name would be capitalized.   

For this action in the text field insert the fn-ToTitleCase function, and put the File Name variable (st_FileName) inside the parenthesis. 

Convert Name To Title Case

5. Remove special characters (regex)

Now we will remove the special characters from the name.  For this we will use another Regex action with the Replace text operation.  In the Pattern field, enter any of the characters you want removed inside a set of brackets.  For your requirements I entered e,-. _].  It might be hard to see on the screen, but I typed open bracket, comma, hyphen, period, space, underscore, closed bracket.  If there were any other characters you wanted to remove, you could add those as well.  

Leave the Replacement text field blank, and use the File Name variable (st_FileName) as both the input text, and to store the results.

Regex Remove Special Characters

6. Build File Name

Now we can construct the full edited File Name.  We will use a Build string action to concatenate the file name with the file extension.  In the text box insert the File Name (st_FileName) and File Extension (st_FileExtension) variables without a space.  Store the results back into the File Name variable. 

Build File Name

7. Set Value

 Finally we can update the Document Name.  Use a Set field value action.  Set the document Name equal to the File Name variable (st_FileName)

Set Document Name

You will now have a formatted document name.  Let me know if you have any questions. 


,

Please let us know if your issue is resolved. It would help others if you can mark the appropriate response as correct answer.


Thanks so much for sharing this solution, it works very well!

I did run into several issues that I haven't been able to resolve yet, although they are probably simple (I am relatively new to Nintex).

  1. If a file is uploaded with a name that needs changing (eg - test file name.pdf) the workflow processes it perfectly, renaming it to TestFileName.pdf. However, if the user tries to upload it again with the original file name again 'test file name.pdf', it causes an error.
  2. If a file is uploaded using the desired formatting (eg - TestFileName.pdf) it gets renamed to Testfilename.pdf (without desired capitalization in the middle).
  3. If a file is added via Windows Explorer view, the workflow is not started at all (The ‘Allow start when items are modified’ option is set to no, for specific reason).

If anyone has any insight to share on the above questions, I would be grateful. Thanks in advance!


Reply