4

I'm using Sharepoint 2013, but this particular site workflow is a 2010 version. I'm trying to accomplish this in Sharepoint Designer.

This workflow creates a new document, and assigns a given number to it. To determine the number I'm retrieving a numeric value from a particular list. After getting this value I need to add leading zeros to it before concatenating it with another string. For instance, the value I get back might be 4, and I want it to have a total of 3 characters, so in this case 004. A value of 12 should be formatted 012, and so on.

An alternate approach I tried was using calculated fields rather than putting this together within the workflow. Unfortunately this isn't a comprehensive solution for me as I need the formatted value available as a Word Quick Part, and as far as I know calculated fields cannot be used for this.

  • I don't have the "Build Dynamic String" option as an available action. I'm guessing that's in a different type of workflow. I had to use a 2010 workflow in order to get the document created properly (based on a word template) as doing this via a 2013 workflow always created a corrupt file. – user3267837 Dec 19 '14 at 16:42
  • I think "build dynamic string" is the old name. You cannot find this action but you can still use the function. Check it out – Mark L Aug 30 '16 at 1:55
3

following solution worked for me: https://www.linkedin.com/groups/Auto-Incrementing-Document-IDs-Help-43166.S.196916024

After I tried all kinds of formula's, solution turned out to be much easier, say: plain simple.

Solution from the link above:

If you need the leading 0s and I understand what you're looking for correctly, I think it can be accomplished with three SharePoint Designer workflow actions and using the ID field on the document library: -Create a column that will be your DocId and set it as type "single line of text"

-You'll want to modify that column in the Content Type definition to be of type Hidden so that users can't modify this column when editing properties of a document in the library.

  • Create a SPD workflow and add a "Set Workflow Variable" action. Create a new variable "TempDocId" and when you set the value select the ... button and then type in 0000000 then press the "Add or Change Lookup" and insert a reference to the ID column of the current item. This gives you a variable that has the unique ID plus (too many) 0s in front of it

  • Next add the "Extract substring from end of string" workflow action. Change the number 0 to 6 and change the text "string" to be a reference to the workflow variable we created above "TempDocId".

  • Finally add a "Set Field in Current Item" workflow action and set the current item's DocId field to the value that's in the "substring" workflow variable (result from above).

0

You can use the following formula and set the result to a variable. Or use this in a calculated field

=CONCATENATE("STRINGTOPREFIX",REPT("0",MAX(0,3-LEN(ID))),ID)

Replace ID with the value you read from the list.

  • Hi, thanks for the response. I've tried something very similar to this (and it's how I previously got the calculated field to properly concatenate those values). Trouble is, I can't get this formula to work inside of a workflow. It adds the number, but treats the rest of it as a string, and ignores the Concatenate and Rept functions (interpreting that as part of the string). – user3267837 Dec 18 '14 at 23:33
  • I think you should break the steps (1) Read the number (2) set variable and use the REPT to format the number (3) concatenate – Amal Hashim Dec 18 '14 at 23:34
  • Same result, unfortunately. The string builder in the workflow doesn't seem to recognize the functions. The exact contents of my example is: =REPT("0",MAX(0,3-LEN([%Variable: AutoNum%]))) But for a value of AutoNum of 10, instead of the output being 010, it's "=REPT("0",MAX(0,3-LEN(10)))" – user3267837 Dec 18 '14 at 23:49
  • Ok then I think event receivers is the next option. Or use IF conditions and check the length then add 0 and build the string. – Amal Hashim Dec 18 '14 at 23:51
0

I tend to use a sandboxed custom workflow action for this kind of requirements. You can simply write an AddLeadingZeros custom action and use it in your workflows.

I appreciate this requires Visual Studio etc to develop, but I did this only once, I maintain a solution which holds all sorts of small actions to do this kind of tasks and I simply add a few lines when I need a new functionality.

Here is a link on how to do it: Link

0

You can do a calculated value field, then in the workflow assign a text field to that calculated value. Then you can use that text field in other areas where you cannot use a calculated value. Such as an indexed field. I'm doing this in Sharepoint Online and SPD 2013 for the workflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.