- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 07:37 AM
Hi all,
Greetings. I have created an application called Transfer Tracker. I wanna auto populate the short description, description field if changed the filed name called Ticket_Number. Ticket_number field is Reference field from Incident Table. Please find the below script. Also find the attached files for the field types which I have created
DescriptionField
Short Description
Form for Transfer Tracker
TicketNumber Field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
}
var incSD=g_form.getReference('u_ticket_number',populate);
function populate(incSD){
if(incSD.short_description){
g_form.setValue('u_ttshort_description',incSD.short_description);
g_form.setValue('u_tt_description',incSD.description);
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 08:02 AM
Hi,
It looks like your code is outside of the onChange function.
Please try the following version:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var incSD = g_form.getReference('u_ticket_number', populate);
function populate(incSD) {
if (incSD && incSD.short_description) {
g_form.setValue('u_ttshort_description', incSD.short_description);
g_form.setValue('u_tt_description', incSD.description);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 07:58 AM
Hi,
I suggest that you look at existing onChange Client Scripts for working examples. Also see:
and in general:
https://developer.servicenow.com/dev.do#!/reference/api/utah/client/c_GlideFormAPI
There are many examples there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 08:02 AM
Hi,
It looks like your code is outside of the onChange function.
Please try the following version:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var incSD = g_form.getReference('u_ticket_number', populate);
function populate(incSD) {
if (incSD && incSD.short_description) {
g_form.setValue('u_ttshort_description', incSD.short_description);
g_form.setValue('u_tt_description', incSD.description);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 08:25 AM
Hi Isais,
Thanks a lot for the reply. In Previous assignment group field, its showing sys ID I guess instead of Group name please find the attachment.
And the script is given below
Regards..
Mani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 09:07 AM
setValue has an additional parameter to specify a display value
You can try:
g_form.setValue('u_previous_assignment_group', incSD.assignment_group, incSD.assignment_group.getDisplayValue());