- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 09:41 PM
When the checkbox of this field " This request is for myself " is true then auto populate as logged in user otherwise not
1 This request is for myself : [ ✔️]
2 Requested for : should autopopulate logged in user
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 09:46 PM - edited 01-22-2024 09:50 PM
Simply you can write a onChange client script and populate the logged in user using GlideUser API and g_form.setValue('req for var backend name',g_user.userID)
var userID = g_user.userID;
alert('Current user ID = ' + userID);
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 09:46 PM - edited 01-22-2024 09:50 PM
Simply you can write a onChange client script and populate the logged in user using GlideUser API and g_form.setValue('req for var backend name',g_user.userID)
var userID = g_user.userID;
alert('Current user ID = ' + userID);
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 10:57 PM
Hello @Dhanaja Rode ,
Please give a try to the code below and let me know how it works for you.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
// Get the checkbox value
var isForMyself = g_form.getValue('this_request_for_myself');
// Get the Requested for field element
var requestedForField = g_form.getControl('requested_for');
// If the checkbox is checked, auto-populate with the logged-in user
if (isForMyself) {
var loggedInUser = g_user.userID;
g_form.setValue('requested_for', loggedInUser);
// Optionally, you can disable the Requested for field if it's auto-populated
requestedForField.disabled = true;
} else {
// If the checkbox is unchecked, clear the Requested for field
g_form.setValue('requested_for', '');
// Optionally, you can enable the Requested for field if it was disabled
requestedForField.disabled = false;
}
}
This script assumes that the checkbox field has the variable name 'this_request_for_myself' and the Requested for field has the variable name 'requested_for'. Adjust the variable names accordingly based on your actual field names.
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket