One of the projects I’m doing now is connecting HR.Net system with our Active Directory. Every time new employee start, we want to create a new user in AD and inform the manager about new account with the password.
So we have a table that stores usernames, passwords and other relevant information. To generate username we just take furst name and lastname, combine them together. Problem here would be with the password: we want to have it random for every new user. But HR.Net can not generate random strings.
What I thought might be a solution here: create a new computed field of type text, take primary key of this table and convert it into text, take first 6 characters from guid-string.
Don’t forget you are working with HR.Net from Vizual.. and nothing is simple there. Computed field did not work as required.
Here is the SQL I want to have as a computation: SUBSTRING( CONVERT( VARCHAR(36), people_id ), 0,6 ), having people_id as guid lookup to People table. But for some reason stupid validation mechanism in HR.Net did not let me do this – it did not allow me to have fields of type guid to be present in computation sql. WHY??? why the hell not have guid in computation?? VIZUAL? why not? please reveal this world-class secret..
Anyway, instead of people_id I’ve put in newid() function, so in HRNET it looks like this: SUBSTRING( CONVERT( VARCHAR(36), NEWID() ), 0,6 ). Then I went to backend SQL Server and changed the properties of this computed field – changed the function to what I require and saved it.
In HR.Net computation string still remains the same – probably it is saved somewhere else, but actual computation takes place in SQL Server.
Everybody is happy now.. apart from Vizual developers who had to implement this silly validation.