1

I've got a list in SP2013 that consists of three fields: Category, LastNumber, and NextNumber - we'll call it ListA. All three fields are of type String (Single Line of Text). This list is used by a workflow that automatically assigns ID numbers to items from other lists according to a numeric category number. The workflow on each list does the following steps:

  1. finds the category on ListA that matches the one on the current item
  2. sets a field in the current item to the NextNumber value from ListA
  3. updates the LastNumber value on ListA to the one just assigned
  4. updates the NextNumber value on ListA to the LastNumber plus one

This process has worked well, but we recently added a new category that starts with a zero, and apparently the increment (step #4) is dropping the zero off the front of the number. This results in a totally different number. All category values are seven digits.

How can I tell SharePoint and/or the the workflow to keep the leading zero?

3
  • is NextNumber a number field? if it's the case - it's a normal behavior. 01234567 is the same as 1234567 – Denis Molodtsov Mar 9 '18 at 21:11
  • @DenisMolodtsov - no, all three fields on ListA are strings. I'll add that to the question, although now you've got me wondering if the workflow is temporarily treating it like an integer. – Omegacron Mar 9 '18 at 21:53
  • You'll have to write custom code or function to add the zero back if it's present. By using a mathematical function to increase the value in step 4, the leading zero will always be dropped. – jpollar Mar 11 '18 at 2:42
3

Numeric types do not have leading zeros. You will need to concatenate zeros to the beginning of number and then use "Extract substring from end of string" action extract the right most X characters.

1234
"00000" + 1234    = 000001234
right 5 characters =   01234

You would:

  1. Use "Set workflow variable" and the string builder to concatenate the zeros and the number into a new variable.
  2. Use the ""Extract substring from end of string" to get the right most "x" characters into another variable.
  3. Use the "Set field in current item" to write the zero padded variable back to the list.
1
  • This probably would have worked as well, but I ultimately went with a simpler workaround. I'll post it as an answer. – Omegacron Apr 6 '18 at 16:33
0

The field in question is formatted as a string, but in order to calculate the next number (by adding 1 or more to the existing number), we had to use workflow variables with a type of "integer". The problem was coming into play at that point, because integers cannot start with a zero and it was therefore being dropped off.

Efforts to stop the dropoff from occurring kept failing because the value could only be converted to a string AFTER the calculation, and the workflow was automatically dropping the zero at the same time as the calculation.

Ultimately, the solution I came up with - or workaround, rather - was to go into ListA and add a zero to the front of both the LastNumber and NextNumber columns, but only for this one category that could potentially have a leading zero.

As a result, items assigned to the category have TWO zeros at the front, and the workflow drops off the first zero, resulting in the correct number being assigned. Since "NextNumber" also has two zeroes, the loop continues next time a number is assigned. Other categories that start with a non-zero value continue to calculate normally.

If nothing else, SharePoint admin work requires a certain amount of inventiveness...

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.