Sometimes when You create list You are in need of some ID number that is meaningful in its form. And you need it before you can fill all the required fields as well it should base on previous row.
Example – We are creating inventory of computers and acquiring first available host name base on Company Name and next available number in this case row ID.
My approach is quite blunt and not as sophisticated as some known solutions using time and separate id tables that are often mention on other articles. And because of that it will not work in every scenario and also have some few major obvious drawback but at the same time it is easy and clean. And more often than not it is more important that its disadvantages.
- We have an example list with two columns Hostname (Unique and Required)
and Serial Number (Required – with default value 000-0000)
- In InfoPath we create a custom form and add Button to it.
Now we need to add couple of rules to this button.
- First we crate Action this action will do as fallow (If ID Blank Then Save and Generate Hostname)
- This rule have one condition ( ID is Blank)
- Set HostName to temporary value (Company#)
- Send Date to List
Set HostName value base on item ID.
concat(„Company”; substring(„000”; 1; 3 – string-length(ID)); ID)
This is string operation that will join string company and string 000 – number of char in ID and at the end join ID
Important: Use insert filed in formula to put ID into formula. Also verify formula before save
- Send Data to SharePoint again.
- Set Serial Number value to blank so it will require User to input the correct value.
To be aware that this procedure can be messy if users will not think before clicking Hostname Generator. On the other hand this is full puff to duplicated Unique ID and it is fairly easy to implement. I also like to add discard button that will delete row after so if record was created by mistake users will have easy way to delete it instead of searching it on the list and removing manually. This will generate gap in ID but at least will keep the list clean.
I hope this will be handful for some of you. Till next time.