Incident form customized filed auto population of user details

khasim523169
Tera Contributor

Hi Team

i have created a custom filed on incident form back end name :(u_t_id), i want to auto populate the user details on customized filed 

 

i have used on load client script , but it is not working 

// Get the user ID from the current user var userId = g_user.userID; // Set the caller_id field with the user ID g_form.setValue("caller_id", userId); // Get the reference record for the caller_id field var callerId = g_form.getReference("caller_id"); // Get the username from the reference record and set u_t_id field if (callerId) { var username = callerId.username; g_form.setValue("u_t_id", username); } 

 

Regards

khasim

4 REPLIES 4

Sonam_Tiwari
Kilo Sage

Hi @khasim523169 ,

 

Modified a bit. Try once.

 

// Get the user ID from the current user
var userId = g_user.userID;
g_form.setValue('caller_id',userId);

// Get the reference record for the caller_id field
var callerId = g_form.getReference("caller_id", setUTID);
// Callback function to handle the reference record
function setUTID(callerId) {
   
    var username = callerId.user_name; // Adjust this line based on your user structure
    alert(username);
    g_form.setValue("short_description", username);
}

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @khasim523169 

 

Incident already have caller field , any reason to create another field and get value?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Dear Atul

 

i am just trying , is it possible to set the user details in customs filed (which was created by user).. through client script

 

Regards

khasim

 

Yes, why not. Use scripts and work done buddy. 

 

Keep Learning N Keep Growing. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************