- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2024 11:34 PM
Hello Everyone,
I am trying to auto fill the userid base on the first initial and lastname that i input.
I able to do it using OnSubmit, but what I want to achieve is to use OnChange so that everytime I create a new record in sys_user table it will automatically fill-up the User ID field depends on the first initial firstname and full lastname.
Can anyone knows how to achieve this ? Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2024 12:59 AM
Are you creating all of these manually? If it's through automation, you can't use client side scripting for it.
Also: I would stick with the 'submit' functionality. It will do exactly the same and you only have one script running. To get this through client script, you will need two: one onChange of first name, one onChange of last name, because the order of filling them can differ (or a typo correction on either of the fields).
That having said, if you still really want 2 scripts running, you can do it like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var firstName = g_form.getValue('first_name');
var lastName = g_form.getValue('last_name');
if (firstName && lastName) {
var initial = firstName.charAt(0) + '.';
var fullName = initial + lastName;
g_form.setValue('user_id', fullName);
}
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2024 12:59 AM
Are you creating all of these manually? If it's through automation, you can't use client side scripting for it.
Also: I would stick with the 'submit' functionality. It will do exactly the same and you only have one script running. To get this through client script, you will need two: one onChange of first name, one onChange of last name, because the order of filling them can differ (or a typo correction on either of the fields).
That having said, if you still really want 2 scripts running, you can do it like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var firstName = g_form.getValue('first_name');
var lastName = g_form.getValue('last_name');
if (firstName && lastName) {
var initial = firstName.charAt(0) + '.';
var fullName = initial + lastName;
g_form.setValue('user_id', fullName);
}
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2024 04:03 PM
Hello,
Yes you are correct its created manually on sys_user table. so everytime I input record in firstname and lastname it will populate into userid.
Thanks for your feedback
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 02:20 AM
Hi @Jeck Manalo ,
Instead of creating new Client script, why don't you use Calculated value in dictionary configuration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 03:53 AM
Calculated fields have impact on performance. Especially when the field is displayed on lists (and we are talking about the user table, so it's on a lot of lists).
Next to that: ordering on calculated fields often doesn't work and again: it's the user table, so the chances are that you want to order on them every now and then.
So yes, calculated fields will work, but in this case, just don't use it.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark