We are delighted to share our new EIC Delivery Methodology for efficiently managing Saviynt Implementations and delivering quick time to value. CLICK HERE.

Username based on dynamic attributes example

New Contributor
New Contributor

Hi team,

I am working on a usecase for the Create New User tile where I have created Username field as a dynamic attribute where I am trying to create a 7 digit alphanumeric random string based on firstname and lastname fields provided in the form itself.

Has anyone implemented anything of this sort and could give me an example string? I've referred to this article - https://forums.saviynt.com/t5/ars/various-usage-of-dynamic-attributes/ta-p/37329 - but the code given here does not work. The code here is:

SELECT concat(LPAD(FLOOR(RAND() * 999999.99), 3, '0'), substring('${if(binding.variables.containsKey("FirstName")){ FirstName } else {''}}',1,1),substring('${if(binding.variables.containsKey("MiddleName")){ MiddleName } else { if(binding.variables.containsKey('FirstName')){ FirstName } else {''}}}',1,1),substring('${if(binding.variables.containsKey("LastName")){ LastName } else {''}}',1,1), LPAD(FLOOR(RAND() * 999999.99), 4, '0')) AS id FROM users WHERE 'id' NOT in (SELECT username FROM users) and 'Yes'=${isGenerateUUID} LIMIT 1

I customized it according to my fields but it gave an error. Tried the below as well:

SELECT concat(substring('${if(binding.variables.containsKey("firstname")){ firstname } else {''}}',1,1),substring('${if(binding.variables.containsKey("lastname")){ lastname } else {''}}',1,6)) AS id FROM users WHERE 'id' NOT in (SELECT username FROM users)

Please let me know if there are any current application of this usecase.



Saviynt Employee
Saviynt Employee

Hi @savuser17 

Can you elaborate on your username generation logic? If you can explain your logic then I can help out with the appropriate query.



For example - first letter of first name, followed by 5 letters of last name, followed by random integer. Something of that sort is what we're looking at.