Autopopulate a field on the incident form from the user table

DEESN
Tera Contributor

I've watched countless YouTube videos, read numerous Community articles and still I cant seem to populate a field from the User table on the incident form based on the caller_id. I created a dictionary entry called T-ID and made it a reference and then created various scripts including Client scripts and script includes and cant seem to get it to work. I even tried to use the user's email in case we accidentally set up the dictionary entry wrong and I cant get that to populate either (this was previously configured for us). 

 

Trying to understand if I missed a step in the process. Any help would be appreciated! Here is a very rudimentary outline of what I did:

 

Step 1. Created a dictionary entry for T-ID (reference to the sys_user table)

Step 2: Added the field to the incident form 

Step 3: Created a client script (tried so many versions at this point that writing them out seems unreasonable) to pull caller_id (field name for us is contact) and return the T-ID (u_t_id)

Step 4: Create a Script Includes 

 

18 REPLIES 18

@DEESN 

if u_t_id is reference then it just needs sysId

If your requirement is to auto-populate u_t_id with Contact then simply use this script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}

	if(newValue == '')
		g_form.clearValue('u_t_id');

	g_form.setValue('u_t_id', newValue);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

 

Okay this is the closest I've gotten to success! Right now it's autopopulating but it's the wrong field...

DEESN_0-1704810126542.png

 

Did I incorrectly set up the dictionary entry? I checked the sys_user table to make sure the correct data was in the T-ID column and it is. 

DEESN_2-1704810226649.png

 

 

 

T-ID is referencing the user table, so it will display the user record.

In your user table, is T-ID a string or reference. If it is a reference to a different table, you should have the same reference table instead of user in incident table.

Otherwise I would suggest making it a string field.


Please mark this response as correct or helpful if it assisted you with your question.

Okay we are getting closer and closer but I think I need to make some additional adjustments and definitely need some explaining for understanding.

 

We have the T-ID in the user table as a string.

DEESN_0-1704826360801.png

 

Based on your suggestion (which I dont quite follow why this wouldnt be a reference)  I changed the other dictionary entry for T-ID on our incident table to a string (I tried both the string and the Full UTF-8 (is one better over the other?)) 

DEESN_1-1704826598059.png

 

Now when you open a ticket in the UI view the correct T-ID is displayed but when changed to another caller T-ID becomes a string of characters.

 

This is the coding we currently have in our client script per a member of the community in this thread)

DEESN_2-1704826742082.png

 

In the SOW nothing populates in the T-ID field. I didnt think there were separate dictionary entries. I thought you just had to add the field to each form.

 

I really appreciate your help so far!

you client script should be

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}

if (newValue == ''){
g_form.clearValue('u_t_id');
}
else
{
var gr = g_form.getReference('caller_id');
var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function

function doAlert(caller) { //reference is passed into callback as first arguments
g_form.setValue('u_t_id',caller.u_t_id);
}

}
}

 


Please mark this response as correct or helpful if it assisted you with your question.