- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 10:19 PM
How can I create a custom field on the Incident form that automatically populates with the current user's name?
Solved! Go to Solution.
- 1,607 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 10:34 PM - edited ‎09-29-2024 10:36 PM
Hi @mahesh009
1.Navigate to the Incident form.
2.Right-click on the form header and select Configure > Form Layout.
3.In the Form Layout, under the Available section, click on Create New Field ,field type 'String' .
4.in Client scripts create new onload script
ex:
(function executeRule(current, previous /*null when async*/) {
var userName = gs.getUser().getDisplayName();
g_form.setValue('u_current_user', userName);
})(current, previous);
Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."
Regards,
Manikanta. Kota
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 10:53 PM
Hi @mahesh009
When we open the incident table, we can configure the form layout and create new custom field to the incident form.
And we can write a client script on the incident table onchange() to auto populate the field on the new field.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 10:59 PM
Hi @mahesh009 ,
To automatically populate the "assigned_to" field on the Incident form with the current user's name, you can either use a Business Rule or a Client Script.
Business Rule:
- Create a new Business Rule on the Incident table.
- Set the "When to run" condition to "Before Insert".
- In the script, assign the current user's name to the "assigned_to" field using current.assigned_to = gs.getUser().name;.
Client Script:
- Create a new Client Script on the Incident table.
- Set the "Type" to "OnLoad".
- In the script, set the value of the "assigned_to" field to the current user's name using g_form.setValue('assigned_to', g_user.name);.
Choose the method that best suits your requirements based on whether you need the field to be populated before or after the incident is saved.
Regards,
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 11:34 PM
Hi @mahesh009
we can choose the method that best suits your requirements based on whether you need the field to be populated before or after the incident is saved.
Business Rule:
- Create the custom field
- To populate the field Automatically, we have create business rule
- in adavanced tab ,add a script
if (current.u_current_user.nil()) { // Check if the field is empty
current.u_current_user = gs.getUser().getName(); // Get current user's name
}
Client Script:
- Create a new Client Script on the Incident table.
- Set the "Type" to "OnLoad".
- In the script, set the value of the "assigned_to" field to the current user's name using
g_form.setValue('assigned_to', g_user.name);
.
Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."
Regards,
Venkata Sai Krishna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 11:47 PM
Hi @mahesh009
You Can Add Client Script for Auto-Population:
To automatically populate this field with the current user's name, you need to create a client script:
- Navigate to System Definition > Client Scripts.
- Click on New to create a new client script.
- Fill out the form as follows:
- Name: Give it a descriptive name (e.g., "Auto-populate Current User").
- Table: Select Incident.
- Type: Choose onLoad.
In the script section, add the following code:
function onLoad() { // Get current user's name
var userName = g_user.getDisplayName(); // Set value to custom field
g_form.setValue('u_current_user', userName);
}
Thanks, and Regards
Vishaal
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 12:43 AM
Hi @mahesh009 ,
Refer these items to get your work done.., These can help you to find better Solution.
===================================***************=========================================
"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
Thanks & Regards,
Aditya
=====================================***********==========================================
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 11:34 PM
Hi @mahesh009
we can choose the method that best suits your requirements based on whether you need the field to be populated before or after the incident is saved.
Business Rule:
- Create the custom field
- To populate the field Automatically, we have create business rule
- in adavanced tab ,add a script
if (current.u_current_user.nil()) { // Check if the field is empty
current.u_current_user = gs.getUser().getName(); // Get current user's name
}
Client Script:
- Create a new Client Script on the Incident table.
- Set the "Type" to "OnLoad".
- In the script, set the value of the "assigned_to" field to the current user's name using
g_form.setValue('assigned_to', g_user.name);
.
Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."
Regards,
Venkata Sai Krishna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 11:47 PM
Hi @mahesh009
You Can Add Client Script for Auto-Population:
To automatically populate this field with the current user's name, you need to create a client script:
- Navigate to System Definition > Client Scripts.
- Click on New to create a new client script.
- Fill out the form as follows:
- Name: Give it a descriptive name (e.g., "Auto-populate Current User").
- Table: Select Incident.
- Type: Choose onLoad.
In the script section, add the following code:
function onLoad() { // Get current user's name
var userName = g_user.getDisplayName(); // Set value to custom field
g_form.setValue('u_current_user', userName);
}
Thanks, and Regards
Vishaal
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 12:43 AM
Hi @mahesh009 ,
Refer these items to get your work done.., These can help you to find better Solution.
===================================***************=========================================
"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
Thanks & Regards,
Aditya
=====================================***********==========================================