How to autopopulate name of logged in user in field on a form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 05:27 AM
I have a form where a field needs to be populated with name of logged in user. I am using an on load script however it is not working, (I have checked the UI type to ALL).
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 05:31 AM
function onLoad() {
// Get the current user's name
var userName = g_user.getFullName();
// Set the value of the field
g_form.setValue('field_name', userName);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 05:38 AM
What if 2 users have the same name? Wouldn't sys_id be the unique value for every user?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 06:16 AM
In such cases, it's a good idea to use a more unique identifier, such as the user's email or user ID
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 06:18 AM
Can you help with the code for user id? I have written one above but it doesn't seem to be workinh