- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2024 09:28 PM
I have a requirnmnet , on Incident Form caller should be autopopulated based on current logdin user in ServiceNow.
Can anyone help with code ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 07:15 AM
Yes you can use g_user API in client script and gs.getUser() will work
g_form.setValue('caller_id', g_user.userID);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:17 AM
@SandeepKSingh You can create an onLoad client script on the incident form to populate logged in user on the incident form.
function onLoad() {
// Check if the form is new (to avoid changing the caller on existing incidents)
if (g_form.isNewRecord()) {
// Set the 'Caller' field to the logged-in user
g_form.setValue('caller_id', g_user.userID);
}
}
Please mark the solution helpful and accepted solution if it manages to address your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 11:28 PM
As you requested :-
PFB full script :-
function onLoad() {
if (g_form.isNewRecord()) {
if (!g_form.getValue('caller_id')) {
g_form.setValue('caller_id', g_user.userID);
}
}
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 11:37 PM
You can you the above in case of Service Catalog also as in Service catalog we have variables which you can access based on catalog client script and auto-populate current lodging user on the catalog form
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 07:15 AM
Yes you can use g_user API in client script and gs.getUser() will work
g_form.setValue('caller_id', g_user.userID);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:17 AM
@SandeepKSingh You can create an onLoad client script on the incident form to populate logged in user on the incident form.
function onLoad() {
// Check if the form is new (to avoid changing the caller on existing incidents)
if (g_form.isNewRecord()) {
// Set the 'Caller' field to the logged-in user
g_form.setValue('caller_id', g_user.userID);
}
}
Please mark the solution helpful and accepted solution if it manages to address your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:22 AM
@SandeepKSingh My response addresses your question in an efficient way. It should also be an accepted solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 09:01 AM
Hello @SandeepKSingh ,
Use this script to auto-populate the Caller field:
function onLoad() {
// Check if the form is new (Caller field should be empty)
if (g_form.isNewRecord()) {
// Set the Caller field with the sys_id of the logged-in user
g_form.setValue('caller_id', g_user.userID);
}
}
Alternative Approach :
Set a Default Value for the Caller Field -- At the dictionary level have the default value as javascript:gs.getUserID()
If you found my rsponse helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!