- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2016 02:39 PM
I will like to use the transform map to create a unique username from firstname an lastname plus a number 3+3+4
So a name like this
Ex. 1 # Lars Larsen will be LAR (3 from firstname) LAR (3 from lastname) 1985 (a random number)
So the username is LARLAR1985
Ex. 2 # Lars W. Larsen will be LAR (3 from firstname) LAR (3 from lastname) 1985 (a random number)
So the username is LARLAR1856
But before the creating of the username, it have to check the sys_user table if the username is already where.
Hope you got the idea
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2016 03:13 PM
With the assumptions that the import only creates new user records and the first and last field names try this in a field map script.
var first = source.u_firstname.slice(0,3);
var last = source.u_lastname.slice(0,3);
var uid = first + last + Math.floor((Math.random() * 9999) + 1000);
var i = 0;
var gr = new GlideRecord('sys_user');
while (i == 0){
if (gr.get('user_name', uid)){
uid = first + last + Math.floor((Math.random() * 9999) + 1000);
} else {
i = 1;
}
}
answer = uid;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2016 02:53 PM
Is this import only to create new users?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2016 03:13 PM
With the assumptions that the import only creates new user records and the first and last field names try this in a field map script.
var first = source.u_firstname.slice(0,3);
var last = source.u_lastname.slice(0,3);
var uid = first + last + Math.floor((Math.random() * 9999) + 1000);
var i = 0;
var gr = new GlideRecord('sys_user');
while (i == 0){
if (gr.get('user_name', uid)){
uid = first + last + Math.floor((Math.random() * 9999) + 1000);
} else {
i = 1;
}
}
answer = uid;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 01:37 AM
Thanks. Its looking nice
I did forgot to write that we have special danish character, so I have ÅØÆand åøæ in the username, is there a way to change the character to this:
Ã… = A
ÃËœ = O
Æ= A
Ã¥ = a
ø = o
æ = a
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 03:39 AM
Or better have a list over accepted character a-z.
Can I use this one?
I find this on google.
By adding our .cleanup()
method to the String object itself, you can then cleanup any string in Javascript simply by calling a local method, like this:
# Attaching our method to the String Object String.prototype.cleanup = function() { return this.toLowerCase().replace(/[^a-zA-Z0-9]+/g, "-"); }
# Using our new .cleanup() method var clean = "Hello World".cleanup(); // "hello-world"